• Like
Data structure programs in c++
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Data structure programs in c++

  • 514 views
Published

 

Published in Technology , Career
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
514
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
41
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. //bubble sort #include<iostream.h> #include<conio.h> void main () { int a[8] = {22,33,55,44,11,77,11,66}; int k,ptr,temp; const int n = 8; clrscr(); for(k=0;k<=n-2;k++) { ptr=0; while (ptr<=n-k-2) { if(a[ptr] > a[ptr+1]) { temp = a[ptr]; a[ptr] = a[ptr+1]; a[ptr+1] = temp; } ptr = ptr+1; } } for(k=0;k<=7;k++) cout<<a[k]<<"t"; getch(); } // insertion sort #include<iostream.h> #include<conio.h> void main() { clrscr(); int array[10],i,j,k,temp, loc; cout<<"enter the array"<<endl; for(i=0;i<=9;i++) cin>>array[i]; //insertion sort logic for (i=1;i<=9;i++) { temp=array[i];
  • 2. loc=i; for (j=i;j>=1;j--) { if (temp < array[j-1]) { array[j] = array[j-1]; loc=j-1; } else break; } array[loc]=temp; } cout<<"sorted arry"<<endl; for(k=0;k<=9;k++) cout<<array[k]<<" "; getch(); } //sum of two variables( not in salybas) #include<iostream.h> #include<conio.h> void main() { int a,b,sum; a=3; b=5; sum=a+b; cout<<"enter the first numbr"<<a; cin>>a; cout<<"enter the second number"<<b; cin>>b; cout<<"sum is "<<sum; cin>>sum; getch(); } // to find the angle( not in salybas) #include<iostream.h> #include<conio.h> void main() { int degree,angle; cout<<"enter the degree"; cin>>degree;
  • 3. { if(degree<90) cout<<"the angle is = acute angle"; else if(degree>90) cout<<"the angle is = obtus angle"; else if(degree==90) cout<<"the angle is = right angle"; } getch(); } // to find the largest element #include<iostream.h> #include<conio.h> void main () { int k,i,loc,max,a[5]; clrscr(); cout<<"enter the 5 element"<<endl; for(i=0;i<=4;i++) cin>>a[i]; k=0; loc=0; max=a[0]; while(k<=4) { if(max<a[k]) { loc=k; max=a[k]; } k=k++; } cout<< "locatin is"<<loc<<" "<<"number is "<<max; getch(); } // selection sort #include<iostream.h> #include<conio.h> void main() { clrscr(); int arry[10],i,j,k,temp;
  • 4. cout<<"enter the array"<<endl; for(i=0;i<8;i++) cin>>arry[i]; for(i=0;i<8;i++) for(j=i+1;j<8;j++) if(arry[i] > arry[j]) { temp = arry[i]; arry[i] = arry[j]; arry[j] = temp; } cout<<"sorted arry"<<endl; for(k=0;k<8;k++) cout<<arry[k]<<" "; getch(); } //linear search #include<iostream.h> #include<conio.h> void main() { int item,data[10] = {33,44,55,22,11,66,99,88,77,60},k,loc; clrscr(); cout<<"enter the value to search"<<endl; cin>>item; loc=-1; k = 0; while (loc==-1 && k<=9) { if(item==data[k]) loc=k; k = k+1; } if(loc==-1) cout<<"item is not in an array"; else cout<<loc<<"t"<<"is the location of an item"; getch(); } // quadric equation #include<iostream.h> #include<conio.h> void main () { int a,b,c,d,x,x1,x2;
  • 5. clrscr(); cout<<"enter three values"<<endl; cin>>a>>b>>c; d= b*b -4*a*c; if(d>0) { x1=(-b+d^(1/2)); x2=(-b-d^(1/2)); cout<<x1<<"t"<<x2; } else if(d==0) { x=-b/2*a; cout<<"uniqe solution"<<x; } else cout<<"no real soltuion"; getch(); }