Cole G. Botin
Cole G. Botin
#include <bits/stdc++.h>
//global
int i;
int row,col;
//function
void convert2DimSort(int list[],int dim);//convert one dimensional to 2-dimensional for both option 1
and 2
void get2DOut(int list1[][sizeCol]);//displaying the values in ascending and descending order 2-D
void heapifyAlgo(int arr1[], int n1, int i1);//for heapifying arr and helper function for heap sort
int main()
char sagot;
do
char choice='y';
sagot=getMenu(choice);
switch(sagot)
case '1'://bubblesort
int dim=20;
int list[20];
getInput(list,dim);
getBubble(list,dim);
//call convert2DimSort
convert2DimSort(list,dim);
break;
case '2':
int dim=20;
int list[20];
getSelect(list,dim);
//call convert2DimSort
convert2DimSort(list,dim);
break;
case '3'://heapsort
int size=10;
int arr[10];
for(int i=0;i<10;i++)
int s;
cin>>s;
arr[i]=s;
getHeap(arr,size);
cout<<endl;
for(int i=0;i<10;i++)
{
cout<<"Arr["<<i+1<<"] :"<<arr[i]<<endl;
break;
//exit code
exit(1);
char c;
while(1)
tryAgain();
cin>>c;
if(c=='y'||c=='n')
break;
if(c=='n'){
break;
} while(1);
}
/////////////////////////////////
//menu function
char ch;
if(ans=='y')
cout<<"----------SORTING----------"<<endl;
cout<<"[1]bubble sort"<<endl;
cout<<"[2]selection sort"<<endl;
cout<<"[3]heap sort"<<endl;
cout<<"[4]QUIT "<<endl;
cout<<"---------------------------"<<endl;
cin>>ch;
if(ch=='1'||ch=='3'||ch=='2'||ch=='4')
return ch;
else
return -1;
////////////////////////////////////
for(int i=0;i<20;i++)
cout<<"loc"<<"["<<i<<"]"<<":";
int a;
cin>>a;
list[i]=a;
//////////////////////////////////////
int inList[sizeRow][sizeCol];
int t=0;
for(int i=0;i<sizeRow;i++)
for(int j=0;j<sizeCol;j++)
inList[i][j]=list[t];
//cout<<list[t]<<" ";
t++;
}
}
get2DOut(inList);
////////////////////////////////////////////////
cout<<"Ascending Order\n";
for(int i=0;i<sizeRow;i++)
for(int j=0;j<sizeCol;j++)
//print output
cout<<right<<setw(5)<<list1[i][j]<<" ";
cout<<endl;
cout<<"\nDescending Order\n";
for(int i=sizeRow-1;i>=0;i--)
for(int j=sizeCol-1;j>=0;j--)
cout<<endl;
////////////////////////////////////////////
int i, j;
swap(list[j], list[j+1]);
///////////////////////////////////////////////
int i, j, min_idx1;
min_idx1 = i;
min_idx1 = j;
// Swap
swap(list[min_idx1], list[i]);
//////////////////////////////////////////////
largest1 = l1;
largest1 = r1;
if (largest1 != i1)
swap(arr1[i1], arr1[largest1]);
// Recursively heapify
//getHeap function
//swap element
swap(list3[0], list3[i]);
//call heapify
heapifyAlgo(list3, i, 0);
///////////////////////////////////////////////
//tryAgain function
void tryAgain()