Skip to content

Instantly share code, notes, and snippets.

View Satyamch12's full-sized avatar

Satyam Chaudhary Satyamch12

View GitHub Profile
@Satyamch12
Satyamch12 / add.cpp
Created January 26, 2024 18:13
Addition Program using C++
#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: ";
@Satyamch12
Satyamch12 / add.c
Created January 26, 2024 18:09
Addition Program using C
#include <stdio.h>
int main() {
int num1, num2;
// Input from user
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
@Satyamch12
Satyamch12 / quick sort.cpp
Last active May 1, 2023 09:08
Quick Sort in C
#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)
@Satyamch12
Satyamch12 / algorithm_quicksort.cpp
Created May 1, 2023 09:02
Quick Sort Algorithm
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 }
}
@Satyamch12
Satyamch12 / pseudocode_quicksort.cpp
Created May 1, 2023 08:58
Quick Sort Pseudo Code
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
@Satyamch12
Satyamch12 / linearsearch_function.cpp
Created April 27, 2023 08:45
Linear Search in C with function
#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;
}
@Satyamch12
Satyamch12 / mergesort.cpp
Created April 21, 2023 11:02
Merge Sort C Program
#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;
@Satyamch12
Satyamch12 / algorithm_mergesort.cpp
Created April 21, 2023 06:21
Merge Sort Algorithm
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
@Satyamch12
Satyamch12 / pseudocode_mergesort.cpp
Last active April 21, 2023 06:14
Merge Sort Pseudo Code
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
@Satyamch12
Satyamch12 / algorithm_bubblesort.cpp
Created April 18, 2023 08:30
Bubble Sort Algorithm
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]