Showing posts with label design analysis and algorithm. Show all posts
Showing posts with label design analysis and algorithm. Show all posts

Monday, February 7, 2011

design analysis and algorithm

/ *5. BREADTH FIRST SEARCH */#include#includeint a[10][10],visited[10],n; void search_from1(int); void main() { int i,j; clrscr(); cout<<"\n Enter the number of nodes:"; cin>>n; cout<<"\n Enter the adjancency matrix:\n"; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(i!=j) { cout<<"\nEnter the value of "<cin>>a[i][j]; } cout<<"\n Nodes are visited in the order"; for(i=1;i<=n;i++) if(visited[i]==0) search_from1(i); getch(); } void search_from1(int z) { int i,j; cout<<"-->"<visited[z]=1; for(i=1;i<=n;i++)...

design analysis and algorithm

/*1. MERGE SORT USING DIVIDE AND CONQUER METHOD */#include#includeclass mergesort { int a[20]; void merge(int,int,int); public: void create(int); void merge_sort(int,int); void print(int); }; void mergesort :: create(int n) { int i; cout<<"\n Enter the array elements\n"; for(i=0;icin>>a[i]; } void mergesort :: merge_sort(int p,int r) { int q; if(p{ q=((p+r)/2); merge_sort(p,q); merge_sort(q+1,r); merge(p,q,r); } } void mergesort :: merge(int x,int y,int z) { int n1=y-x+1,n2=z-y,i,j,k,l[20],r[20]; for(i=1;i<=n1;i++)...