Category: Analysis and Design of Algorithms
Frequency of Letter
Generic Bubble Sort in C/C++
template <class T> void Bubble(T *Array, int size){ int temp; int counter=1; while(counter){ counter=0; for(int i=0; i<(size-1); i++){ if(Array[i]>Array[i+1]){ counter=1; temp=Array[i]; Array[i]=Array[i+1]; Array[i+1]=temp; } } } }
Generic Selection Sort in C/C++
template <class T> void Selection(T *Array, int size){ int pos; T min; for(int i=0; i<(size-1); i++){ min=Array[i]; pos=i; for(int j=i+1; j<size; j++){ if(Array[j]<min){ min=Array[j]; pos=j; } } if(pos!=i){ Array[pos]=Array[i]; Array[i]=min; } } }
Generic Insertion Sort in C/C++
template <class T> void Insertion (T *Array, int size){ T temp; int i; for(int j=1; j<size; j++){ temp=Array[j]; i=j-1; while(i>=0 && Array[i]>temp){ Array[i+1]=Array[i]; i=i-1; } Array[i+1]=temp; } }