Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

#include <iostream>

#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
//merge,heap,quick sort left
void merge_sort(int v,int n)//merge sort
{
//combinare de 2 vectori gata sortati
int t[50],u[50],i,j,k,aux;
for(i=1;i<=n;i++)
for(j=1;j<50;j++)
t[j]=v[i];
for(i=50;i<100;i++)
for(k=1;k<50;k++)
u[k]=v[i];
bubble(t,50);
bubble(u,50);
}
void insertion_sort(int v,int n)//insertion sort
{
int i,j,min,aux;
for(i=1;i<n;i++)
{
min=i;
for(j=i+1;j<=n;j++)
{
if(a[j]<a[min])
min=j;
aux=a[i];
a[i]=a[min];
a[min]=aux;
}
}
for(i=1;i<=n,i++)
cout<<v[i]<<' ';
return ;
}
void bubble(int v,int n)//BUBBLE SORT
{
int passes=0,aux=0;
for(passes=0;passes<=(n-1);passes++)
for(j=1;j<=n;j++)
if(v[i]>v[i+1])
{
aux=v[i];
v[i]=v[i+1];

v[i+1=aux;
}
for(i=1;i<=n;i++)
cout<<v[i]<<' ';
return;
}
void selection(int v,int n)//SELECTION SORT
{
int i,j,min,aux;
for(i=0;i<=(n-1);i++)
{
min=i;
for(j=(i+1);j<=n;j++)
{
if(v[j]<v[min])
min=j;
}
aux=v[i];
v[i]=v[min];
v[min]=aux;n
for(i=0;i<=n;i++)
cout<<v[i]<<' ';
return;
}
void shellsort(int v,int n)//SHELLSORT
{
int j,i,m;
for(m = n/2;m>0;m/=2)
{
for(j = m;j< n;j++)
{
for(i=j-m;i>=0;i-=m)
{
if(a[i+m]>=a[i])
break;
else
{
n = a[i];
a[i] = a[i+m];
a[i+m] = n;
}
}
}
}
}
int main()

{
int v[100],i,aux,j;
char option;
FILE *f;
f=fopen("Data.txt","r");
for(i=1;i<=100;i++)
fscanf(f,"%d",v[i]);
LOOP:again
cout<<"Press :\n1) A for "<<setcolor(red)<<"bubble"<<" sort.\n2) B for
"<<setcolour(red)<<"selection"<<" sort.\n3) C for "<<setcolour(red)<<"insertion"<<" sort.\n4) D for
"<<setcolour(red)<<"shell"<<" sort.\n";
cout<<"5) E for "<<setcolour(red)<<"merge"<<" sort.\n6) F for "<<setcolour(red)<<"heap"<<"
sort.\n7) G for "<<setcolour(red)<<"quick"<<" sort.\n8) H to close.\n";
cout<<"Now choose your sorting method : "<<endl;
cin>>v;
switch (option);
{
case "A" : cout<<bubble(v,100);
goto again;
case "B" : cout<<selection(v,100);
goto again;
case "c" : cout<<insertion(v,100);
goto again;
case "D" : cout<<shell(v,100);
goto again;
case "E" : cout<<merge(v,100);
goto again;
case "F" : cout<<heap(v,100);
goto again;
case "G" : cout<<quick(v,100);
goto again;
case "H" : break;
}

You might also like