Documente Academic
Documente Profesional
Documente Cultură
#include<iostream.h>
#include<conio.h>
int a[10][10],visited[10],n;
void dfs(int k);
void main()
{
clrscr();
cout<<"\n Enter the number of nodes";
cin>>n;
cout<<"\n give connection \n\n {for no connection = 0 connection =1}";
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j)
{
cout<<"\n\n connection from ["<<i<<"] to ["<<j<<"]:";
cin>>a[i][j];
cout<<"\n";
}
cout<<"\n\n node are visited in following order->\t";
for(j=1;j<=n;j++)
if(visited[j]==0)
dfs(j);
}
void dfs(int k)
{
int i,j,x; //" hhhhhhhhhhhhhhhhhhhhhhhhhhhh;
for(x=1;x<=n;x++)
{
if(k!=x)
getch();
}
cout<<k;
visited[k]=1;
for(i=1;i<=n;i++)
{
if(visited[j]==0)
if(a[k][i])
dfs(j);
getch();
//break;
}
}
OUTPUT:
give connection
#include<iostream.h>
#include<conio.h>
int a[10][10],visited[10],n;
void bfs(int k);
void main()
{
clrscr();
cout<<"\n Enter the number of nodes";
cin>>n;
cout<<"\n give connection \n\n {for no connection = 0 connection =1}";
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j)
{
cout<<"\n\n connection from ["<<i<<"] to ["<<j<<"]:";
cin>>a[i][j];
cout<<"\n";
}
cout<<"\n\n node are visited in following order->\t";
for(i=1;i<=n;i++)
if(visited[i]==0)
bfs(i);
}
void dfs(int k)
{
int i;
cout<<k;
visited[k]=1;
for(i=1;i<=n;i++)
{
if(visited[i]==0)
if(a[k][i])
dfs(i);
getch();
//break;
}
}
OUTPUT:
give connection
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<string.h>
class is
{
public:
void read_list(int a[],int n);
void print_list(int a[],int n);
void insert_sort(int a[],int n);
};
}
OUTPUT
PASS:1 :: 5 6 3 2 1
PASS:2 :: 3 5 6 2 1
PASS:3 :: 2 3 5 6 1
PASS:4 :: 1 2 3 5 6
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<string.h>
class sc
{
public:
void read_list(int a[],int n);
void print_list(int a[],int n);
void select_sort(int a[],int n);
};
PASS : 0 :: 2 5 25 7 6
PASS : 1 :: 2 5 25 7 6
PASS : 2 :: 2 5 6 7 25
PASS : 3 :: 2 5 6 7 25
PASS : 4 :: 2 5 6 7 25
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<string.h>
class qs
{
public:
void read_list(int a[],int n);
void print_list(int a[],int n);
void quick_sort(int a[],int first,int last);
};
do
{
while(a[low]<pivot)
low++;
while(a[high]>pivot)
high--;
if(low<=high)
{
temp=a[low];
a[low]=a[high];
a[high]=temp;
low=low+1;
high=high-1;
}
}while(low<=high);
if(first<high)
quick_sort(a,first,high);
if(low<last)
quick_sort(a,low,last);
}
void main()
{
qs vid;
int a[20],n;
clrscr();
cout<<"\n\n\t ENTER THE ARRAY LENGTH :: ";
cin>>n;
vid.read_list(a,n);
cout<<"\n\n\t THE ARRAY ELEMENTS ARE AS FOLLOWS :: ";
vid.print_list(a,n);
vid.quick_sort(a,0,n-1);
cout<<"\n\n\t THE SOTED LIST IS :: ";
vid.print_list(a,n);
getch();
}
OUTPUT
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[50],size,max,min;
cout<<"enter the size of the array?";
cin>>size;
cout<<"enter the elements in an array?";
for(int i=0;i<size;i++)
{
cin>>a[i];
max=a[0];
}
for(i=0;i<size;i++)
{
if(a[i]>max)
{
max=a[i];
min=a[0];
}
}
for(i=0;i<size;i++)
{
if(a[i]<min)
min=a[i];
}
cout<<"\n the max and min elements are"<<max<<" "<<min;
getch();
}
OUTPUT