This file contains 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
{ | |
int z = a + b + c; | |
return(z); | |
} |
This file contains 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
/* Below program is written in C language */ | |
# include <stdio.h> | |
void heapify(int arr[], int n, int i) | |
{ | |
int largest = i; | |
int l = 2*i + 1; | |
int r = 2*i + 2; | |
// if left child is larger than root |
This file contains 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
/* | |
a[] is the array, p is starting index, that is 0, | |
and r is the last index of array. | |
*/ | |
#include <stdio.h> | |
// Lets take a[5] = {32, 45, 67, 2, 7} as the array to be sorted. | |
// merge sort function | |
void mergeSort(int a[], int p, int r) |
This file contains 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
// simple C program for Quick Sort | |
# include <stdio.h> | |
// to swap two numbers | |
void swap(int* a, int* b) | |
{ | |
int t = *a; | |
*a = *b; | |
*b = t; | |
} |
This file contains 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
// C program implementing Selection Sort | |
# include <stdio.h> | |
// function to swap elements at the given index values | |
void swap(int arr[], int firstIndex, int secondIndex) | |
{ | |
int temp; | |
temp = arr[firstIndex]; | |
arr[firstIndex] = arr[secondIndex]; | |
arr[secondIndex] = temp; |
This file contains 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 for carrying out binary search on given array | |
- values[] => given sorted array | |
- len => length of the array | |
- target => value to be searched | |
*/ | |
int binarySearch(int values[], int len, int target) | |
{ | |
int max = (len - 1); | |
int min = 0; |
This file contains 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
class node | |
{ | |
int data; | |
node *next; | |
}; | |
class Stack | |
{ | |
private: | |
node *front; // points to the head of list |
This file contains 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
int Stack::top() | |
{ | |
return front -> data; | |
} |
This file contains 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
void Stack :: pop() | |
{ | |
// if empty | |
if(front == NULL) | |
{ | |
printf( "UNDERFLOW\n" ); | |
} | |
// delete the first element | |
else | |
{ |
This file contains 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
void Stack::push(int d) | |
{ | |
// creating a new node | |
node *temp; | |
temp = new node(); | |
// setting data to it | |
temp->data = d; | |
// add the node in front of list |