this is some thing i designed for my tutorial .. this uses quick sort, insertion, bubble and flag bubble to sort numbers ... you can select one of them and design your code.. i think this code will you but ,, if you have any problem you can contact me.. any way the code here seems to be a bit too much for what you are expecting but .. you will get to know alot about the sorting mechanisms used
/* this is some thing i designed for my tutorial .. this uses quick sort, insertion, bubble and flag bubble to sort numbers ... you can select one of them and design your code.. i think this code will you but ,, if you have any problem you can contact me.. any way the code here seems to be a bit too much for what you are expecting but .. you will get to know alot about the sorting mechanisms used */
#include
#include
using namespace std;
typedef int intarray[];
//acts as a counter to count the no of compares
int compares(int a)
{
static int count = 0;
count += a;
return count;
}
//acts as a counter to count the no of swaps
int swaps(int a)
{
static int count = 0;
count += a;
return count;
}
//checks if not in order
bool notinorder (int a,int b)
{
compares(1);
return (a>b);
}
//generate random numbers
void generate(intarray arr,int size,int low,int high)
{
for (int i = 0 ; i = 0 ; j--)
{
for(int i =0; i <= j;i++)
{
if(notinorder(arr[i],arr[i+1]))
{
swap(arr[i],arr[i+1]);
}
}
}
}
//flagbubble sort
void flagbubble(intarray arr,int size)
{
bool stillwapping = false;
for(int j = size-2;j>= 0 ; j--)
{
for(int i =0; i <= j;i++)
{
if(notinorder(arr[i],arr[i+1]))
{
stillwapping = true;
swap(arr[i],arr[i+1]);
}
}
if (!stillwapping)
break;
}
}
// sift funcrion associated with insertion sort
void sift(intarray arr, int i)
{
int j = i - 1;
while (( j >= 0) && notinorder(arr[j],arr[j+1]))
{
swap(arr[j],arr[j+1]);
j--;
}
}
//insertion sort
void insertion(intarray arr,int n)
{
for(int i=1;i < n;i++)
{
sift(arr,i);
}
}
//find best position associated with exchange sort
int bestpos(intarray arr,int start,int end)
{
int best = start;
for(int j = start + 1; j>c;
if(c=='x') // choices
{
cout<>n;
if((!(cin))) //error checking if integer
{
cout<MAX)
{
n = MAX;
}
//caling and displaying sorts
if(c=='b')
{
cout<<"Numbers Generated... "<
Please use 'Code Tags', i dont know how many times the mods have been telling this.
secondly just pasting too much code is not going to help anyone, sometimes it can even confuse the person. It's better to give as much info as is asked.