+44(0) 1234 567 890
info@domainname.com
Programming Exercises
C++ projects ,C# projects, programming lectures, programming exercises, Programming tutorials
Home
Pages
Portfolio
Blog
Features
Contact
Home
World
Travel
Blog
Posts
Pages
Contact Us
About Us
Registers
Thursday, 20 June 2013
Sorting techniques in data structures with examples Lab 4
12:39
By:
Unknown
on
12:39
Share it Please
Tweet
Example No:1
Create a program that take an array of 10 inputs from the user and generate the sorted out put using the following Algorithms;
Bubble Sort.
Insertion Sort.
Selection Sort.
Merging.
Merge sort.
Source Code:
#include<iostream> #include<conio.h> using namespace std; class Sorting { public: void bubblesort(int aray[]) { cout<<"\n\t\t\t Bubble Sort\n"; int i,temp,j,k,l; for(k=0;k<10;k++) { for(j=0;j<9;j++) { if(aray[j]>aray[j+1]) { temp=aray[j]; aray[j]=aray[j+1]; aray[j+1]=temp; } } } for(l=0;l<10;l++) { cout<<"The Element After Bubble Sort : " <<aray[l]<<endl; } } void insertion_sort(int aray[]) { int i,j,k; cout<<"\n\t\t\t INSERTION SORT\n"<<endl; for(k=0;k<10;k++) { for(i=0;i<9;i++) { if(aray[i]>aray[i+1]) { j=aray[i]; aray[i]=aray[i+1]; aray[i+1]=j; } } } for(i=0;i<10;i++) { cout<<"The sorted element is"<<aray[i]<<endl; } } void selection_sort(int aray[]) { int i=0,j=0,k,l=0,swap=0; cout<<"\n\t\t\t SELECTION SORT\n"<<endl; if(l<aray[i]) { l=aray[i]; k=i; } if(aray[i]>aray[k]) { swap=aray[i]; aray[i]=aray[k]; aray[k]=swap; } do { for(i=0;i<10;i++) { if(aray[j]<aray[i]) { swap=aray[i]; aray[i]=aray[j]; aray[j]=swap; } } j++; } while(j!=10); for(i=0;i<10;i++) { cout<<"The sorted element is"<<aray[i]<<endl; } } void merging(int aray[]) { int end1=0,end2=0; int i=0,*k=0,temp=0; int j=end1; int ; while (i<end1 && j<end2) { if(aray[i]<aray[j]) { temp[k]=aray[i]; i=i+1;k=k+1; } else { temp[k]=aray[j]; j=j+1; k=k+1; } } while (i<end1) { temp[k]=aray[i]; i=i+1; k=k+1; } while (i<end2) { temp[k]=aray[i]; j=j+1; k=k+1; } for(i=0;i<end2;i++) { aray[i]=temp[&i]; } for(i=0;i<10;i++) { cout<<"The sorted element is"<<aray[i]<<endl; } } void merge_sort(int aray[]) { cout<<"\n\t\t\t Merge sort \n"; int end1=0,end2=0; int i=0,j=0,min=0,size=10; for(i=1;i<size;i='2i') { for( j=0;j<size-i;j=j+'2i') { end1=i; end2='2i'; size-j; merging(&aray[j]); } } } }; void main() { Sorting ab; int aray[10],i,choice; cout<<"\n\t\t Element Selection\n"; for(i=0;i<10;i++) { cout<<"Enter The Element : "; cin>>aray[i]; } do{ cout<<" Which process you want to select for sorting ??\n 1.Bubble sort, \n 2.Insertion sort, \n 3.Selection sort, \n 4.Merging , \n 5.Merge sort, \n 6. EXIT."; cin>>choice; if(choice==1) { ab.bubblesort(aray); } if(choice==2) { ab.insertion_sort(aray); } if(choice==3) { ab.selection_sort(aray); } if(choice==4) { cout<<"\n\t\t\t Merging \n"; ab.merging(aray); } if(choice==5) { ab.merge_sort(aray); } getch(); } while(choice!=6); system("pause"); }
Related Articles:
Examples of Basic programs in Data...
Examples of Two Dimensional Array...
Linked list Programming exercises...
Newer Post
Older Post
0 comments:
Post a Comment
Subscribe to:
Post Comments (Atom)
Popular Posts
Download Student Fee Management System Project in c# .net
Download c++ books in Hindi, Gujarati, Tamil and Urdu languages
Free Download Laptop Repairing Videos Course
Download Students Information System using Linked List c++
Students fee management system c++ project with report
30 C++ Programming Books Free Download
Address Book Project in C#
How use Labels,Textboxes & buttons In Visual C#.Net
Download Encryption and Decryption Project in c++
Download Typing Master Project in C#
Home
Free Download Video Tutorials
Free Download Projects
Free Download University Lectures
Free Download Programming E Books
Free Download Programming Softwares
Sitemap
Links
ASP.NET Project
C # .net project
c plus plus projects
C# windows applications
C# windows forms Projects
computer science Lectures and Tutorials
Data Structure Labs Solutions
Data Structure Projects
Download videos courses
Mathematics
MBA & BBA Lectures and Tutorials
Programming books
Repairing Videos Courses
Visual C#.Net Exercises
0 comments:
Post a Comment