عنوان پروژه
سورس پیاده سازی روشهای مرتب سازی زبان سی
توضیحات :
سورس کد کلیه روش های مرتب سازی Bubble Sort (مرتب سازی حبابی) – مرتب سازی Insertion Sort (مرتب سازی درجی) – مرتب سازی Selection Sort (مرتب سازی انتخابی) – مرتب سازی Sell Sort (مرتب سازی شل)
نوع فایل |
فرمت |
---|---|
سورس زبان سی |
CPP , EXE |
پیش نمایش از سورس کد پروژه
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void bubblesort(float[],int );
void insertionsort(float[],int);
void selectionsort(float[],int);
void shellsort(float[],int);
void print(float[],int);
void read(float[],int);
void main()
{
char wtc=’y’;
while(wtc==’y’||wtc==’Y’)
{
clrscr();
int choice,n;
float a[200];
printf(“Enter the size of array”);
scanf(“%d”,&n);
printf(“\n”);
printf(“Enter %d integers of array”,n);
read(a,n);
printf(“\n Enter the following numbers to use the following techniques:\n”);
printf(“\t1.BUBBLE SORT\n”);
printf(“\t2.INSERTION SORT\n”);
printf(“\t3.SELECTION SORT\n”);
printf(“\t4.SHELL SORT\n”);
printf(“\n”);
printf(“Enter your choice”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:
{
bubblesort(a,n);
print(a,n);
getch();
break;
}
case 2:
{
insertionsort(a,n);
print(a,n);
getch();
break;
}
case 3:
{
selectionsort(a,n);
print(a,n);
getch();
break;
}
case 4:
{
shellsort(a,n);
print(a,n);
getch();
break;
}
}
cout<<“\n\n Do you want to continue(y/n)”;
cin>>wtc;
}
getch();
}
void read(float a[],int n)
{
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void bubblesort(float a[],int n)
{
for(int p=0;p<(n-1);p++)
{
for(int i=0;i<n-1;i++)
{
if(a[i]>a[i+1])
{
float temp;
temp=a[i+1];
a[i+1]=a[i];
a[i]=temp;
}
}
}
}
void insertionsort(float a[],int n)
{
for(int i=1;i<n;i++)
{
float x=a[i];
int j=i;
while(j>0 && a[j-1]>x)//definition of insertion sort
a[j–]=a[j-1];
a[j]=x;
}
}
void shellsort(float a[],int n)
{
int gap; int swap;
gap=n/2;
int k=0;
do{
do{
swap = 0;
k++;
int i;
for(i=0;i<n-gap;i++)
if(a[i]>a[i+gap])
{
int temp;
temp=a[i];
a[i]=a[i+gap];
a[i+gap]=temp;
swap = 1;
}
======