Deque at and Deque Swap in C++ Programming STL

Sunidhi Bansal
Updated on 05-Mar-2020 10:53:35

204 Views

In this article we will be discussing the working, syntax and examples of deque::at() and deque::swap() functions in C++ STL.What is Deque?Deque is the Double Ended Queues that are the sequence containers which provides the functionality of expansion and contraction on both the ends. A queue data structure allow user to insert data only at the END and delete data from the FRONT. Let’s take the analogy of queues at bus stops where the person can be inserted to a queue from the END only and the person standing in the FRONT is the first to be removed whereas in ... Read More

Compare Numbers in Python

Samual Sam
Updated on 05-Mar-2020 10:48:16

17K+ Views

You can use relational operators in python to compare numbers(both float and int) in python. These operators compare the values on either side of them and decide the relation among them. Assume variable a holds 10 and variable b holds 20, thenOperatorExample==(a == b) is not true.!=(a != b) is true.>(a > b) is not true.=(a >= b) is not true.= b) print(a

Find Hash of File Using Python

Arjun Thakur
Updated on 05-Mar-2020 10:46:21

3K+ Views

You can find the hash of a file using the hashlib library. Note that file sizes can be pretty big. Its best to use a buffer to load chunks and process them to calculate the hash of the file. You can take a buffer of any size.Exampleimport sys import hashlib BUF_SIZE = 32768 # Read file in 32kb chunks md5 = hashlib.md5() sha1 = hashlib.sha1() with open('program.cpp', 'rb') as f: while True:    data = f.read(BUF_SIZE)    if not data:       break    md5.update(data)    sha1.update(data) print("MD5: {0}".format(md5.hexdigest())) print("SHA1: {0}".format(sha1.hexdigest()))OutputThis will give the outputMD5: 7481a578b20afc6979148a6a5f5b408d SHA1: ... Read More

List Emplace Front and Emplace Back in C++ STL

Sunidhi Bansal
Updated on 05-Mar-2020 10:45:30

759 Views

In this article we will be discussing the working, syntax and examples of list::emplace_front() and list::emplace_back() function in C++ STL.What is a List in STL?List is a data structure that allows constant time insertion and deletion anywhere in sequence. Lists are implemented as doubly linked lists. Lists allow non-contiguous memory allocation. List performs better insertion extraction and moving of element in any position in container than array, vector and deque. In List the direct access to the element is slow and list is similar to forward_list, but forward list objects are single linked lists and they can only be iterated ... Read More

Find ASCII Value of Character using Python

Chandu yadav
Updated on 05-Mar-2020 10:39:47

220 Views

The ord function in python gives the ordinal value of a character(ASCII). You can use this function to find the ascii codes as followsExamples = "Hello" for c in s:    print(ord(c))OutputThis will give the output72 101 108 108 111

Set Value Comp Function in C++ STL

Sunidhi Bansal
Updated on 05-Mar-2020 10:39:37

274 Views

In this article we are going to discuss the set::value_comp() in C++ STL, their syntax, working and their return values.What is Set in C++ STL?Sets in C++ STL are the containers which must have unique elements in a general order. Sets must have unique elements because the value of the element identifies the element. Once added a value in set container later can’t be modified, although we can still remove or add the values to the set. Sets are used as binary search trees.What is set::value_comp()?value_comp() is an inbuilt function in C++ STL which is declared in header file. ... Read More

Convert Decimal to Binary, Octal and Hexadecimal using Python

karthikeya Boyini
Updated on 05-Mar-2020 10:38:46

1K+ Views

Python provides straightforward functions to convert Decimal to Binary, Octal, and Hexadecimal. These functions are −Binary: bin() Octal: oct() Hexadecimal: hex()ExampleYou can use these functions as follows to get the corresponding representation −decimal = 27 print(bin(decimal),"in binary.") print(oct(decimal),"in octal.") print(hex(decimal),"in hexadecimal.")OutputThis will give the output −0b11011 in binary. 0o33 in octal. 0x1b in hexadecimal.

Set Upper Bound Function in C++ STL

Sunidhi Bansal
Updated on 05-Mar-2020 10:37:59

1K+ Views

In this article we are going to discuss the set::upper_bound() in C++ STL, their syntax, working and their return values.What is Set in C++ STL?Sets in C++ STL are the containers which must have unique elements in a general order. Sets must have unique elements because the value of the element identifies the element. Once added a value in set container later can’t be modified, although we can still remove or add the values to the set. Sets are used as binary search trees.What is set::upper_bound()?upper_bound() is an inbuilt function in C++ STL which is declared in header file. ... Read More

Display Multiplication Table Using Python

Ankith Reddy
Updated on 05-Mar-2020 10:36:28

415 Views

You can create the multiplication table for any number using a simple loop. exampledef print_mul_table(num):    for i in range(1, 11):       print("{:d} X {:d} = {:d}".format(num, i, num * i)) print_mul_table(5)OutputThis will give the output5 X 1 = 5 5 X 2 = 10 5 X 3 = 15 5 X 4 = 20 5 X 5 = 25 5 X 6 = 30 5 X 7 = 35 5 X 8 = 40 5 X 9 = 45 5 X 10 = 50

Find the Largest Among Three Numbers using Python

Samual Sam
Updated on 05-Mar-2020 10:35:19

1K+ Views

You can create a list of the three numbers and call the max method to find the largest among them. examplemy_list = [10, 12, 3] print(max(my_list))OutputThis will give the output −12ExampleIf you want to calculate it yourself, you can create a simple function likedef max_of_three(a, b, c):    if a > b and a > c:       return a    elif b > c:       return b    else:       return c print(max_of_three(10, 12, 3))OutputThis will give the output −12

Advertisements