PDA

View Full Version : مبتدی: سورس کدهای درس طراحی الگوریتم



m.aghasi68
جمعه 09 دی 1390, 09:47 صبح
الگوریتم های فلوید . جستجوی ترتیبی .جستجوی خطی و....

m.aghasi68
جمعه 09 دی 1390, 09:49 صبح
الگوریتم فلوید #include <stdio.h>
#include <conio.h>
#include <iostream.h>
void main(void)
{
clrscr();
int i,j,k,n,m,l,h,x,y,z,f[10][10],d[10][10],p[10][10];
cout<<"enter number node";
cin >> n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf ("f[%d][%d]=",i,j);
cin >>x;
f[i][j]=x;

}
cout<<"\n" << "matris mojaver geraf is=arraye f " << "\n\n";
//==============================================
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{ d[i][j]=f[i][j];
cout << "\t" <<f[i][j];
}
cout<< "\n\n";
}
//===============================================
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{

l=(d[i][k]+d[k][j]);
h=d[i][j];
if(l < h)
d[i][j]=l;
}
cout <<"\n"<<"small distane betwen nodes"<<"\n\n";
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cout << "\t" <<d[i][j];
}
cout<< "\n\n";
}

//=============================enter 2 node==================
cout << "enter 2 node for find smallest distance betwen 2 node";
cin >> y >> z;
cout <<"the smallest distance is:" << d[y][z];
//================================================== ==========

getch();
}

با کد C++

m.aghasi68
جمعه 09 دی 1390, 09:51 صبح
Algoritm Quick Sort

CoDe Nevisi Ba C++

#include <conio.h>
#include <stdio.h>
int s[255];
int counter=0;
//************partition***********
void partition(int low,int high,int *pivotpoint)
{
int i,j,temp;
int pivotitem;

pivotitem=s[low];
j=low;
for (i=low+1;i<=high;i++)
{
if (s[i]<pivotitem)
{
j++;
temp=s[i];
s[i]=s[j];
s[j]=temp;
counter++;
}
}
*pivotpoint=j;
temp=s[low];
s[low]=s[*pivotpoint];
s[*pivotpoint]=temp;
counter++;
}
//***********quicksort************
void quicksort(int low,int high)
{
int pivotpoint;
if (high>low)
{
partition(low,high,&pivotpoint);
quicksort(low,pivotpoint-1);
quicksort(pivotpoint+1,high);
}
}
int main(void)
{
int n;
clrscr();
printf("\enter a count number:");
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
printf("\n s[%d]=",i);
scanf("%d",&s[i]);
}
quicksort(1,n);
for (int i=1;i<=n;i++)
{
printf("\n s[%d]=%d",i,s[i]);
}
printf("\n %d",counter);
getch();
return 0;
}
//****************quicksort*******