Author Archives:
Merge Sort in C++
Been a while since I posted some code here, this one I’m posting to help a junior from NSIT out. #include <iostream.h> int *Arr, maxSize; void createArr() { cout<<"\n\n Enter the maximum size of array : "; cin>>maxSize; Arr = new int[maxSize]; } void fillArr() { cout<<"\n\n Enter the elements [...]
Fibonacci Series (Using Recursion) in C++
This is a simple 2 statement function that takes n as an argument and returns the nth Fibonacci number. Can be used to display the Fibonacci series upto the integer size limit. #include <iostream.h> #include <conio.h> unsigned int fibonacci (unsigned int n) { if (n <= 2) { return 1; } else { [...]
Linear Search in C++
Oh yeah, they ask us to make Linear Search TOO. This code is as simple as it gets. Sorry, but making it any simpler would make my eyes bleed. Here you go. #include <iostream.h> #include <conio.h> int linearSearch(int*, int, int, int); int main() { int *sArray, mSize, i, elem, index; cout<<"\n [...]
Binary Search in C++
Now the important thing to note here is that Binary Search only has a meaning when your input is sorted in some way, using some parameter as basis for sorting. This program implements binary search for a set of integers, sorted in ascending order. Binary search on an unsorted input makes no sense as if [...]