This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main() { | |
int num1, num2; | |
// Input from user | |
std::cout << "Enter the first number: "; | |
std::cin >> num1; | |
std::cout << "Enter the second number: "; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
int num1, num2; | |
// Input from user | |
printf("Enter the first number: "); | |
scanf("%d", &num1); | |
printf("Enter the second number: "); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
void quicksort(int number[50], int first, int last){ | |
int i,j,pivot,temp; | |
if (first<last) | |
{ | |
pivot=first; | |
i=first; | |
j=last; | |
while(i<j) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUICKSORT (array A, start, end) | |
{ | |
1 if (start < end) | |
2 { | |
3 p = partition(A, start, end) | |
4 QUICKSORT (A, start, p - 1) | |
5 QUICKSORT (A, p + 1, end) | |
6 } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function partitionFunc(left, right, pivot) | |
start = left | |
end = right - 1 | |
while True do | |
while A[++start] < pivot do | |
end while | |
while end > 0 && A[--end] > pivot do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int linear_search (int a[],int size,int key) | |
{ | |
int j; //key -> Required element, | |
for(j=0;j<size;j++) | |
{ | |
if(a[j]==key) | |
{ | |
return j; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
// merge function | |
void Merge(int arr[], int left, int mid, int right) | |
{ | |
int i, j, k; | |
int size1 = mid - left + 1; | |
int size2 = right - mid; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MERGE_SORT(array, start, end) | |
if start < end | |
set mid = (start + end)/2 | |
MERGE_SORT(array, start, mid) | |
MERGE_SORT(array, mid + 1, end) | |
MERGE (array, beg, mid, end) | |
end of if | |
END MERGE_SORT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: Declare the variable start and end | |
Step 2: start will equal 0, and end will equal array size -1. | |
Step 3: Calculate mid using start + end / 2. | |
Step 4: Call the mergeSort function on the part (start, mid) and (mid+1, end). | |
Step 5: This calling will continue till start<end is satisfied. | |
Step 6: Finally, call the merge function to merge these two halves |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: Start from the first index array [0] and array [1] and | |
compare the first and second element array [0] and array [1] | |
Step 2: If array [0] is greater than array [1] they are swapped | |
Step 3: Similarly, if array[1] is greater than array[2] they are swapped | |
Step 4: The above process continues until the last element array [n-1] |
NewerOlder