New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



Resources » Articles/Knowledge Sharing » Computer & Technology »

Merge Sort


Posted Date: 31 Oct 2009    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology
Author: Dhananjoy ChakrabortyMember Level: Gold    
Rating: 3 out of 53 out of 53 out of 5Points: 5



Suppose there are 8 values in an array and the values are to be sorted using merge sort. The array list is to be divided into 4 sublist each of which contains 2 elements and the sublists are to be sorted. After sorting the sublists, two consecutive lists will be merged to form a new sublists. In our case 2 sublists will be formed and the sublists will be sorted again. The sorting technique can be selection sort, bubble sort or any other. Then again the sublists will be merged and sorting process will continue until it becomes a single list. Then finally the single list will be sorted.
Suppose values are:

66 33 40 22 55 88 60 11
The groups will be like
66 33 40 22 55 88 60 11
After sorting we get
33 66 22 40 55 88 11 60
Now the new group
33 66 22 40 55 88 11 60
After sorting
22 33 40 66 11 55 60 88
The new group
22 33 40 66 11 55 60 88
After sorting
11 22 33 40 55 60 66 88

#include
#include
void sort(int arr[],int top,int size,int bottom)
{
float temp[20];
int f=top;
int s=size+1;
int t=top;
int upper;
while((f<=size)&&(s<=bottom))
{
if(arr[f]<=arr[s])
{
temp[t]=arr[f];
f++;
}
else
{
temp[t]=arr[s];
s++;
}
t++;
}
if(f<=size)
{
for(f=f;f<=size;f++)
{
temp[t]=arr[f];
t++;
}
}
else
{
for(s=s;s<=bottom;s++)
{
temp[t]=arr[s];
t++;
}
}
for(upper=top;upper<=bottom;upper++)
{
arr[upper]=temp[upper];
}
}
void pass(int arr[],int m,int n)
{
if(m!=n)
{
int mid=(m+n)/2;
pass(arr,m,mid);
pass(arr,mid+1,n);
sort(arr,m,mid,n);
}
}
void main()
{
int list[20]={22,1,23,3,43,4,3,2,55,4,5,6,7,11,12,23,45,67,8,9};
int i;
printf("\nElements as follows\n");
for(i=0;i<20;i++)
printf("%4d",list[i]);
pass(list,0,19);
printf("\nElements after sorting---as follows\n");
for(i=0;i<20;i++)
printf("%4d",list[i]);
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Merge Sort  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Hashing in C Language
Previous Resource: Windows 7: The Newest version of Microsoft Windows
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
More Resources



Advertise Here





Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

ISC Technologies.
2006 - 2009 All Rights Reserved.