Linear Search in C++ Linear search is the simplest and traditional searching approach. There is no need to sort the array you can directly search the required value. The approach is using a loop to access each element of the array and check if that element matches with the user-provided value. If the match is found break the loop and print elemen…
Read moreBinary Search in C++ To implement binary search the array must be sorted , if you don't sort it may give the wrong output. Take the array size and array elements. Sort the array in ascending order. Take the element the user wants to search. The trick in binary search is you find the middle element of the array by adding the first and last elem…
Read moreBubble Sort Algorithm In the bubble sort algorithm, the biggest element is bubbled at the end of the array. The algorithm has two loops first one to go through the array normally and the second one will be used for comparison of two array elements and swapping. In the second loop, each array element will be compared to the next one, a…
Read moreSelection sort algorithm The algorithm has two loops one for iteration and the other for comparing. And two variables one(min variable) to store the smallest element and the other(index variable) to store its index. Assign the first element of the array to the min variable and the index variable to zero. Start the second loop from the …
Read moreSort in C++ C++ has an Inbuilt function for sorting. You can sort both in ascending as well as in descending order. The sort function is very useful in array manipulations programs. You just need to give the array name and its size and the STL command does the job The syntax is very simple as shown below. For ascending order sort(array_name, array…
Read moreReverse function in C++: C++ has a built in function to reverse the order of given input. It reverses the order of the elements in the range (first, last) of any input. The time complexity of reverse() is O(n). Program to reverse a given string in C++ #include <bits/stdc++.h> using namespace std; int main() { cout<< "Enter a String: " …
Read moreLoops in C++ There are many problems where you have to perform a particular task again and again for n times. Now writing the code n times is not possible because n can also change. Hence to do such part of the program we use loops. In loops, the code is written once, and then it is performed for n times in a loop. There are 3 types of looping statement 1.…
Read moreConditional Statements in C++ When you start programming there may occur some situation based on the situation you have to perform certain activities for example we consider the result of a student. There are cut off marks if the student score above cut off then he passes otherwise fails the exam. This can be achieved using the ternary operator but there so…
Read moreOperators In C++ The symbols used to perform arithmetic or logical operations on variables are called operators and the entity on which the operation is performed is called an operand. The operators based on operands can be classified into two types Unary operators Binary operators Unary operators: When any operation is performed at that ti…
Read moreCopyright © 2021 Coding Demons All Rights Reseved
Social Plugin