<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2279790585312186476</id><updated>2024-10-05T08:09:09.690+05:30</updated><title type='text'>Data Structures And Algorithms</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-845432477050163672</id><published>2007-06-21T15:01:00.000+05:30</published><updated>2007-06-24T20:47:31.071+05:30</updated><title type='text'>Implementation of Quick Sort</title><content type='html'>&lt;pre&gt;#include&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;&lt;/span&gt;stdio.h&lt;span style=&quot;font-weight: bold;&quot;&gt;&gt;&lt;/span&gt;&lt;br /&gt;#include&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;&lt;/span&gt;stdlib.h&lt;span style=&quot;font-weight: bold;&quot;&gt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;int partition(int a[],int p,int q)&lt;br /&gt;{&lt;br /&gt;   int up,down,temp;&lt;br /&gt;   up=p+1;down=q;&lt;br /&gt;   do&lt;br /&gt;   {&lt;br /&gt;   while(a[down]&lt;span style=&quot;font-weight: bold;&quot;&gt;&gt;&lt;/span&gt;a[p] &amp;&amp;amp;amp; down&gt;p)&lt;br /&gt;       down-=1;&lt;br /&gt;   while(a[up]&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;&lt;/span&gt;a[p])&lt;br /&gt;       up+=1;&lt;br /&gt;   if(up&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;&lt;/span&gt;down)&lt;br /&gt;   {&lt;br /&gt;       temp=a[up];&lt;br /&gt;       a[up]=a[down];&lt;br /&gt;       a[down]=temp;&lt;br /&gt;   }&lt;br /&gt;   }while(up&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;&lt;/span&gt;down);&lt;br /&gt;   temp=a[down];&lt;br /&gt;   a[down]=a[p];&lt;br /&gt;   a[p]=temp;&lt;br /&gt;   return down;&lt;br /&gt;}      &lt;br /&gt;     &lt;br /&gt;void quick_sort(int a[],int p,int q)&lt;br /&gt;{&lt;br /&gt;   int r;&lt;br /&gt;   if(p&lt;span style=&quot;font-weight: bold;&quot;&gt;&gt;&lt;/span&gt;=q)&lt;br /&gt;   return;&lt;br /&gt;   r=partition(a,p,q);&lt;br /&gt;   quick_sort(a,p,r-1);&lt;br /&gt;   quick_sort(a,r+1,q);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc,char *argv[])&lt;br /&gt;{&lt;br /&gt;   int size,*ar,i;  &lt;br /&gt;   printf(&quot;\nEnter the no of elements&quot;);&lt;br /&gt;   scanf(&quot;%d&quot;,&amp;size);&lt;br /&gt;   ar=(int *)malloc(size*sizeof(int));&lt;br /&gt;   printf(&quot;\nEnter the elements\n&quot;);&lt;br /&gt;   for(i=0;i&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;&lt;/span&gt;size;i++)&lt;br /&gt;       scanf(&quot;%d&quot;,&amp;ar[i]);&lt;br /&gt;   quick_sort(ar,0,size-1);&lt;br /&gt;   printf(&quot;\nThe Sorted List is :\n&quot;);&lt;br /&gt;   for(i=0;i&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;&lt;/span&gt;size;i++)&lt;br /&gt;   printf(&quot;%d &quot;,ar[i]);&lt;br /&gt;   printf(&quot;\n&quot;);&lt;br /&gt;   return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/845432477050163672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/845432477050163672' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/845432477050163672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/845432477050163672'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/implementation-of-quick-sort.html' title='Implementation of Quick Sort'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-2716885605646725477</id><published>2007-06-20T23:52:00.000+05:30</published><updated>2007-06-21T00:23:31.906+05:30</updated><title type='text'>Merge Sort Explained</title><content type='html'>Merge sort or Mergesort is an O(n log n) sorting algorithm. It is easy to implement merge sort such that it is stable, meaning it preserves the input order of equal elements in the sorted output. It is an example of the divide and conquer algorithmic paradigm. It is a comparison sort. The algorithm was invented by John von Neumann in 1945.&lt;br /&gt;&lt;br /&gt;Merge sort recursively divides the array of elements into smaller subarrays and sort them and then merge these to form a complete sorted array.&lt;br /&gt;&lt;p&gt;Conceptually, merge sort works as follows:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;Divide the unsorted list into two sublists of about half the size&lt;/li&gt;&lt;li&gt;Divide each of the two sublists recursively until we have list sizes of length 1, in which case the list itself is returned&lt;/li&gt;&lt;li&gt;Merge the two sorted sublists back into one sorted list.&lt;/li&gt;&lt;/ol&gt;Description of the &lt;a href=&quot;http://ds-algo.blogspot.com/2007/06/implementation-of-merge-sort.html&quot;&gt;Implementation of Merge Sort:&lt;/a&gt;&lt;br /&gt;The program contains 2 important functions.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;merge() - This function takes as argument the bounds of parts of array to be merged. These two parts are contiguous and hence only 3 bounds are required. These parts are copied in separate arrays and then actual merging takes place. There are two pointers to the beginning of these arrays. The first elements are compared and smaller one copied to the original array and its pointer incremented. This process continues till one of the arrays exhausts. After this the remaining array is just copied. Thus the two arrays are merged and the result is a sorted array part.&lt;/li&gt;&lt;li&gt;merge_sort() -  This function breaks the array into two nearly equal parts and calls merge_sort for these parts. Then it calls the merge() function to merge these parts.&lt;/li&gt;&lt;/ol&gt;Example:&lt;br /&gt;let the array be 80 32 56 37 69 76.&lt;br /&gt;this is partitioned into 2 parts as&lt;br /&gt;80 32 56 | 37 69 76&lt;br /&gt;&lt;br /&gt;now 80 32 56 is partitioned into 2 parts as&lt;br /&gt;80 | 32 56&lt;br /&gt;&lt;br /&gt;since 80 is single element list, it is trivially sorted.&lt;br /&gt;&lt;br /&gt;now 32 56 is partitioned into 2 parts as&lt;br /&gt;32 | 56&lt;br /&gt;&lt;br /&gt;Again these are trivially sorted.&lt;br /&gt;&lt;br /&gt;Now merge 32 | 56 results in 32 56&lt;br /&gt;&lt;br /&gt;And merge 80 | 32 56 results in 32 56 80&lt;br /&gt;&lt;br /&gt;Now 37 69 76 is partitioned into 2 parts as&lt;br /&gt;37 | 69 76&lt;br /&gt;&lt;br /&gt;since 37 is single element list, it is trivially sorted.&lt;br /&gt;&lt;br /&gt;now 69 76 is partitioned into 2 parts as&lt;br /&gt;69 | 76&lt;br /&gt;&lt;br /&gt;Again these are trivially sorted.&lt;br /&gt;&lt;br /&gt;Now merge 69 | 76 results in 69 76&lt;br /&gt;&lt;br /&gt;And merge 37 | 69 76 results in 37 69 76&lt;br /&gt;&lt;br /&gt;At last merge 32 56 80 | 37 69 76 results in sorted array&lt;br /&gt;32 37 56 69 76 80</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/2716885605646725477/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/2716885605646725477' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/2716885605646725477'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/2716885605646725477'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/merge-sort-explained.html' title='Merge Sort Explained'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-8934428167976088559</id><published>2007-06-18T19:27:00.000+05:30</published><updated>2007-06-24T20:47:55.117+05:30</updated><title type='text'>Implementation of Merge Sort</title><content type='html'>&lt;pre&gt;#include&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;stdio.h&lt;span style=&quot;font-weight:bold;&quot;&gt;&gt;&lt;/span&gt;&lt;br /&gt;#include&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;stdlib.h&lt;span style=&quot;font-weight:bold;&quot;&gt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;void merge(int a[], int p, int q, int r)&lt;br /&gt;{&lt;br /&gt;    int i=0,j=0,k=0,len1,len2;&lt;br /&gt;    len1 = q-p+1;&lt;br /&gt;    len2 = r-q;&lt;br /&gt;    int *a1 = (int *)malloc(len1*sizeof(int));&lt;br /&gt;    int *a2 = (int *)malloc(len2*sizeof(int));&lt;br /&gt;    for(i=p;i&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;=q;i++)&lt;br /&gt;    a1[j++]=a[i];&lt;br /&gt;    j=0;&lt;br /&gt;    for(i=q+1;i&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;=r;i++)&lt;br /&gt;    a2[j++]=a[i];&lt;br /&gt;    i=0;j=0,k=p;&lt;br /&gt;    while(i&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;len1 &amp;&amp;amp; j&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;len2)&lt;br /&gt;    {&lt;br /&gt;    if(a1[i]&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;a2[j])&lt;br /&gt;        a[k++]=a1[i++];&lt;br /&gt;    else&lt;br /&gt;        a[k++]=a2[j++];&lt;br /&gt;    }&lt;br /&gt;    if(i&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;len1)&lt;br /&gt;    {&lt;br /&gt;    for(;i&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;len1;i++)&lt;br /&gt;         a[k++]=a1[i];&lt;br /&gt;    }&lt;br /&gt;    else for(;j&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;len2;j++)&lt;br /&gt;         a[k++]=a2[j];&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void merge_sort(int a[], int p, int r)&lt;br /&gt;{&lt;br /&gt;    int q;&lt;br /&gt;    q = (p+r)/2;&lt;br /&gt;    if(!(q-p&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;=0))&lt;br /&gt;    {&lt;br /&gt;    merge_sort(a,p,q);&lt;br /&gt;    }&lt;br /&gt;    if(!(r-q&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;=1))&lt;br /&gt;    {&lt;br /&gt;    merge_sort(a,q+1,r);&lt;br /&gt;    }&lt;br /&gt;    merge(a,p,q,r);&lt;br /&gt;       &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;int main(int argc,char *argv[])&lt;br /&gt;{&lt;br /&gt;    int size,*ar,i;   &lt;br /&gt;    printf(&quot;\nEnter the no of elements&quot;);&lt;br /&gt;    scanf(&quot;%d&quot;,&amp;size);&lt;br /&gt;    ar=(int *)malloc(size*sizeof(int));&lt;br /&gt;    printf(&quot;\nEnter the elements\n&quot;);&lt;br /&gt;    for(i=0;i&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;size;i++)&lt;br /&gt;        scanf(&quot;%d&quot;,&amp;ar[i]);&lt;br /&gt;    merge_sort(ar,0,size-1);&lt;br /&gt;    printf(&quot;\nThe Sorted List is :\n&quot;);&lt;br /&gt;    for(i=0;i&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;size;i++)&lt;br /&gt;        printf(&quot;%d &quot;,ar[i]);&lt;br /&gt;    printf(&quot;\n&quot;);&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/8934428167976088559/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/8934428167976088559' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/8934428167976088559'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/8934428167976088559'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/implementation-of-merge-sort.html' title='Implementation of Merge Sort'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-7770584212525818414</id><published>2007-06-18T02:15:00.000+05:30</published><updated>2007-06-18T03:11:46.872+05:30</updated><title type='text'>Heap Sort Explained</title><content type='html'>Heap Sort is another optimal comparison sort as its time complexity is O(nlgn) in both average and worst cases. Although somewhat slower in practice on most machines than a good implementation of quicksort, it has the advantages of worst-case O(&lt;i&gt;n&lt;/i&gt; log &lt;i&gt;n&lt;/i&gt;) runtime. Heapsort is an in-place algorithm and is not a stable sort.&lt;br /&gt;The main idea behind heapsort is to construct a heap out of the list of elements to be sorted. From this heap the maximum element (in case of max-heap) or the minimum element (in case of min-heap) can be repeatedly taken out with ease to give the sorted list of elements.&lt;br /&gt;&lt;br /&gt;Description of the &lt;a href=&quot;http://ds-algo.blogspot.com/2007/06/include-stdio.html&quot;&gt;Implementation Of Heap Sort&lt;/a&gt;:&lt;br /&gt;The code uses max-heap for sorting an array. It starts with the macro definitions of left and right children of a node i. The rest of the code consists of 3 functions :&lt;br /&gt;&lt;br /&gt;1) max_heapify()  :  It takes as input the index of node i in an array a whose size is also passed. the node i has the property that both its left and right subtrees are max-heaps. But the tree rooted at node i may not be so. This function makes this tree a max-heap. It traverses the tree starting from node i to the leaves. Every time it compares the node with its left and right children and the maximum of all of them takes the position of the node.&lt;br /&gt;&lt;br /&gt;2) build_max-heap()  :  It is the function for the initial formation of the heap when the sorting starts. It calls max-heapify() function for all non-leaf nodes. This is so because the leaf nodes are trivially max-heaps of size 1. When this function returns, the array becomes a max-heap.&lt;br /&gt;&lt;br /&gt;3) heap_sort() : This function is the main heapsort function. It starts by calling the build_max_heap() function on the array. After this function, the max element of the heap is replaced by the last element in the heap and its size is reduced by 1. Then max_heapify() is called from the root of heap. This is continued till the heap contains no more elements.&lt;br /&gt;&lt;br /&gt;For example, take the max-heap as&lt;br /&gt;87 34 67 20 18 56 40&lt;br /&gt;&lt;br /&gt;Now 87 will be replaced by 40&lt;br /&gt;40 34 67 20 18 56 | 87&lt;br /&gt;after max_heapify()&lt;br /&gt;67 34 56 20 18 40 | 87&lt;br /&gt;&lt;br /&gt;Now 67 will be replaced by 40&lt;br /&gt;40 34 56 20 18 | 67 87&lt;br /&gt;after max_heapify()&lt;br /&gt;56 34 40 20 18 | 67 87&lt;br /&gt;&lt;br /&gt;Now 56 will be replaced by 18&lt;br /&gt;18 34 40 20 | 56 67 87&lt;br /&gt; after max_heapify()&lt;br /&gt;40 34 18 20 | 56 67 87  &lt;span style=&quot;text-decoration: underline;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;Now 40 will be replaced by 20&lt;br /&gt;20 34 18 | 40 56 67 87 &lt;br /&gt; after max_heapify()&lt;br /&gt;34 20 18 | 40 56 67 87&lt;br /&gt;&lt;br /&gt;Now 34 will be replaced by 18&lt;br /&gt;18 20 | 34 40 56 67 87 &lt;br /&gt;   after max_heapify()&lt;br /&gt;20 18 |  34 40 56 67 87&lt;br /&gt;&lt;br /&gt;Now 20 will be replaced by 18&lt;br /&gt; 18 | 20 34 40 56 67 87 &lt;br /&gt;    after max_heapify()&lt;br /&gt;18 |  20 34 40 56 67 87&lt;br /&gt;&lt;br /&gt;Thus the sorted list is  18 20 34 40 56 67 87</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/7770584212525818414/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/7770584212525818414' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/7770584212525818414'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/7770584212525818414'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/heap-sort-explained.html' title='Heap Sort Explained'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-1857383379383194703</id><published>2007-06-13T12:09:00.000+05:30</published><updated>2007-06-24T20:48:33.408+05:30</updated><title type='text'>Implementation Of Heap Sort</title><content type='html'>&lt;pre&gt;#include&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;stdio.h&lt;span style=&quot;font-weight:bold;&quot;&gt;&gt;&lt;/span&gt;&lt;br /&gt;#include&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;stdlib.h&lt;span style=&quot;font-weight:bold;&quot;&gt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;#define left(i) 2*i+1&lt;br /&gt;#define right(i) 2*i+2&lt;br /&gt;&lt;br /&gt;void max_heapify(int a[],int i,int size)&lt;br /&gt;{&lt;br /&gt;    int l,r,largest,temp;&lt;br /&gt;    l=left(i);&lt;br /&gt;    r=right(i);&lt;br /&gt;    if(l&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;=size-1 &amp;&amp;amp; a[l]&lt;span style=&quot;font-weight:bold;&quot;&gt;&gt;&lt;/span&gt;a[i])&lt;br /&gt;        largest = l;&lt;br /&gt;    else largest = i;&lt;br /&gt;    if(r&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;=size-1 &amp;&amp;amp; a[r]&lt;span style=&quot;font-weight:bold;&quot;&gt;&gt;&lt;/span&gt;a[largest])&lt;br /&gt;        largest = r;&lt;br /&gt;    if(largest != i)&lt;br /&gt;    {&lt;br /&gt;        temp = a[i];&lt;br /&gt;        a[i]=a[largest];&lt;br /&gt;        a[largest]=temp;&lt;br /&gt;        max_heapify(a,largest,size);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void build_max_heap(int a[],int size)&lt;br /&gt;{&lt;br /&gt;    int i;&lt;br /&gt;    for(i=size/2 - 1 ;i&lt;span style=&quot;font-weight:bold;&quot;&gt;&gt;&lt;/span&gt;=0;i--)&lt;br /&gt;        max_heapify(a,i,size);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void heap_sort(int a[],int size)&lt;br /&gt;{&lt;br /&gt;    int i,temp;&lt;br /&gt;    build_max_heap(a,size);&lt;br /&gt;    for(i=size-1;i&lt;span style=&quot;font-weight:bold;&quot;&gt;&gt;&lt;/span&gt;0;i--)&lt;br /&gt;    {&lt;br /&gt;        temp=a[i];&lt;br /&gt;        a[i]=a[0];&lt;br /&gt;        a[0]=temp;&lt;br /&gt;        size=size - 1;&lt;br /&gt;        max_heapify(a,0,size);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc,char *argv[])&lt;br /&gt;{&lt;br /&gt;    int size,*ar,i;   &lt;br /&gt;    printf(&quot;\nEnter the no of elements&quot;);&lt;br /&gt;    scanf(&quot;%d&quot;,&amp;size);&lt;br /&gt;    ar=(int *)malloc(size*sizeof(int));&lt;br /&gt;    printf(&quot;\nEnter the elements\n&quot;);&lt;br /&gt;    for(i=0;i&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;size;i++)&lt;br /&gt;        scanf(&quot;%d&quot;,&amp;ar[i]);&lt;br /&gt;    heap_sort(ar,size);&lt;br /&gt;    printf(&quot;\nThe Sorted List is :\n&quot;);&lt;br /&gt;    for(i=0;i&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;&lt;/span&gt;size;i++)&lt;br /&gt;        printf(&quot;%d &quot;,ar[i]);&lt;br /&gt;    printf(&quot;\n&quot;);&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/1857383379383194703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/1857383379383194703' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/1857383379383194703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/1857383379383194703'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/include-stdio.html' title='Implementation Of Heap Sort'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-3380989894808724980</id><published>2007-06-13T00:13:00.000+05:30</published><updated>2008-11-19T08:38:02.138+05:30</updated><title type='text'>Shell Sort Explained</title><content type='html'>Shell Sort works on the principle that removes large amount of disorders quickly. It differs from other sorting algorithms as in early stages far-apart elements are compared rather than adjacent ones. This gap is gradually reduced to one and it becomes an adjacent interchange method.&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEAKpvAXHjC-rKvK0uijtN0K1jtrQyA5ItmLdt7nZC-NSqmk03dBCJn1bKrptvPYaophl_D-Dm3rB-Oo2qBfksumYXJzomgZ8FNubkD0jZcQkrwnxvuuHj4Z39dwW-vLdPnM3VOYqV_8la/s1600-h/shell.JPG&quot;&gt;&lt;img style=&quot;margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 430px; height: 176px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEAKpvAXHjC-rKvK0uijtN0K1jtrQyA5ItmLdt7nZC-NSqmk03dBCJn1bKrptvPYaophl_D-Dm3rB-Oo2qBfksumYXJzomgZ8FNubkD0jZcQkrwnxvuuHj4Z39dwW-vLdPnM3VOYqV_8la/s400/shell.JPG&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5075256207295075346&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;(Image Source: The Art of Computer Programming, vol. 3, D.E. Knuth)&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;The running time of this algorithm is O(&lt;span style=&quot;font-size:100%;&quot;&gt;n^2) which is quite inefficient. But the constant factor is much better than insertion or bubble sort.&lt;br /&gt;&lt;br /&gt;Description of &lt;/span&gt;&lt;a href=&quot;http://ds-algo.blogspot.com/2007/06/implementation-of-shell-sort.html&quot;&gt;Implementation Of Shell Sort&lt;/a&gt;&lt;span style=&quot;font-size:100%;&quot;&gt; :&lt;br /&gt;The  main() function starts by asking the no of elements and then allocates an array of required size. Then the array is filled up and the shell sort function is called. This function does the actual sorting. After that, the sorted array is printed.&lt;br /&gt;&lt;br /&gt;The shell_sort() function starts sorting the array. The outermost for loop takes control of the &quot;gap&quot; between compared elements. In the beginning the gap is half the size of array i.e. elements of one half are compared to corresponding elements in the second half. This gap is gradually reduced to 1. The middle for loop steps along element. The innermost for loop compares elements separated by &quot;gap&quot; and reverses that are out of order.&lt;br /&gt;Since the gap is eventually reduced to 1, all the elements are eventually ordered correctly.        &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/3380989894808724980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/3380989894808724980' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/3380989894808724980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/3380989894808724980'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/shell-sort-explained.html' title='Shell Sort Explained'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEAKpvAXHjC-rKvK0uijtN0K1jtrQyA5ItmLdt7nZC-NSqmk03dBCJn1bKrptvPYaophl_D-Dm3rB-Oo2qBfksumYXJzomgZ8FNubkD0jZcQkrwnxvuuHj4Z39dwW-vLdPnM3VOYqV_8la/s72-c/shell.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-5649158926631298788</id><published>2007-06-11T21:44:00.000+05:30</published><updated>2007-06-24T20:49:17.997+05:30</updated><title type='text'>Implementation Of Shell Sort</title><content type='html'>&lt;pre&gt;#include&lt;b&gt;&lt;&lt;/b&gt;stdio.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;#include&lt;b&gt;&lt;&lt;/b&gt;stdlib.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;void shell_sort(int a[],int size)&lt;br /&gt;{&lt;br /&gt; int i,j,temp,gap;&lt;br /&gt; for(gap=size/2;gap&lt;b&gt;&gt;&lt;/b&gt;0;gap/=2)&lt;br /&gt; {&lt;br /&gt;  for(i=gap;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt;  {&lt;br /&gt;   for(j=i-gap;j&lt;b&gt;&gt;&lt;/b&gt;=0 &amp;&amp; a[j]&lt;b&gt;&gt;&lt;/b&gt;a[j+gap];j-=gap)&lt;br /&gt;   {&lt;br /&gt;    temp=a[j];&lt;br /&gt;    a[j]=a[j+gap];&lt;br /&gt;    a[j+gap]=temp;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc,char *argv[])&lt;br /&gt;{&lt;br /&gt; int size,*ar,i; &lt;br /&gt; printf(&quot;\nEnter the no of elements&quot;);&lt;br /&gt; scanf(&quot;%d&quot;,&amp;size);&lt;br /&gt; ar=(int *)malloc(size*sizeof(int));&lt;br /&gt; printf(&quot;\nEnter the elements\n&quot;);&lt;br /&gt; for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt;  scanf(&quot;%d&quot;,&amp;ar[i]);&lt;br /&gt; shell_sort(ar,size);&lt;br /&gt; printf(&quot;\nThe Sorted List is :\n&quot;);&lt;br /&gt; for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt;  printf(&quot;%d &quot;,ar[i]);&lt;br /&gt; printf(&quot;\n&quot;);&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/5649158926631298788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/5649158926631298788' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/5649158926631298788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/5649158926631298788'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/implementation-of-shell-sort.html' title='Implementation Of Shell Sort'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-3213829584017441746</id><published>2007-06-11T19:37:00.000+05:30</published><updated>2007-06-24T20:49:39.928+05:30</updated><title type='text'>Implementation Of Insertion Sort</title><content type='html'>&lt;pre&gt;#include&lt;b&gt;&lt;&lt;/b&gt;stdio.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;#include&lt;b&gt;&lt;&lt;/b&gt;stdlib.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;void insertion_sort(int a[],int size)&lt;br /&gt;{&lt;br /&gt; int i,j,temp,small;&lt;br /&gt; for(i=1;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt; {&lt;br /&gt;  for(j=i;j&lt;b&gt;&gt;&lt;/b&gt;0;j--)&lt;br /&gt;  {&lt;br /&gt;   if(a[j]&lt;b&gt;&lt;&lt;/b&gt;a[j-1])&lt;br /&gt;   {&lt;br /&gt;    temp=a[j];&lt;br /&gt;    a[j]=a[j-1];&lt;br /&gt;    a[j-1]=temp;&lt;br /&gt;   }&lt;br /&gt;   else&lt;br /&gt;    break;&lt;br /&gt;  }&lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc,char *argv[])&lt;br /&gt;{&lt;br /&gt; int size,*ar,i; &lt;br /&gt; printf(&quot;\nEnter the no of elements&quot;);&lt;br /&gt; scanf(&quot;%d&quot;,&amp;size);&lt;br /&gt; ar=(int *)malloc(size*sizeof(int));&lt;br /&gt; printf(&quot;\nEnter the elements\n&quot;);&lt;br /&gt; for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt;  scanf(&quot;%d&quot;,&amp;ar[i]);&lt;br /&gt; insertion_sort(ar,size);&lt;br /&gt; printf(&quot;\nThe Sorted List is :\n&quot;);&lt;br /&gt; for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt;  printf(&quot;%d &quot;,ar[i]);&lt;br /&gt; printf(&quot;\n&quot;);&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/3213829584017441746/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/3213829584017441746' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/3213829584017441746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/3213829584017441746'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/implementation-of-insertion-sort.html' title='Implementation Of Insertion Sort'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-8962805911972319509</id><published>2007-06-11T19:19:00.000+05:30</published><updated>2007-06-24T20:50:07.108+05:30</updated><title type='text'>Implementation Of Selection Sort</title><content type='html'>&lt;pre&gt;#include&lt;b&gt;&lt;&lt;/b&gt;stdio.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;#include&lt;b&gt;&lt;&lt;/b&gt;stdlib.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;void selection_sort(int a[],int size)&lt;br /&gt;{&lt;br /&gt; int i,j,temp,small;&lt;br /&gt; for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size-1;i++)&lt;br /&gt; {&lt;br /&gt;  small=i;&lt;br /&gt;  for(j=i;j&lt;b&gt;&lt;&lt;/b&gt;size;j++)&lt;br /&gt;  {&lt;br /&gt;   if(a[j]&lt;b&gt;&lt;&lt;/b&gt;a[small])&lt;br /&gt;    small=j;&lt;br /&gt;  }&lt;br /&gt;  temp=a[i];&lt;br /&gt;  a[i]=a[small];&lt;br /&gt;  a[small]=temp;&lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc,char *argv[])&lt;br /&gt;{&lt;br /&gt; int size,*ar,i; &lt;br /&gt; printf(&quot;\nEnter the no of elements&quot;);&lt;br /&gt; scanf(&quot;%d&quot;,&amp;size);&lt;br /&gt; ar=(int *)malloc(size*sizeof(int));&lt;br /&gt; printf(&quot;\nEnter the elements\n&quot;);&lt;br /&gt; for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt;  scanf(&quot;%d&quot;,&amp;ar[i]);&lt;br /&gt; selection_sort(ar,size);&lt;br /&gt; printf(&quot;\nThe Sorted List is :\n&quot;);&lt;br /&gt; for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt;  printf(&quot;%d &quot;,ar[i]);&lt;br /&gt; printf(&quot;\n&quot;);&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/8962805911972319509/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/8962805911972319509' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/8962805911972319509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/8962805911972319509'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/implementation-of-selection-sort.html' title='Implementation Of Selection Sort'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-3209357320375937492</id><published>2007-06-11T14:25:00.000+05:30</published><updated>2007-06-11T19:18:19.890+05:30</updated><title type='text'>Implementation Of Bubble Sort</title><content type='html'>#include&lt;b&gt;&lt;&lt;/b&gt;stdio.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;#include&lt;b&gt;&lt;&lt;/b&gt;stdlib.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;void bubble_sort(int a[],int size)&lt;br /&gt;{&lt;br /&gt;   int i,j,temp;&lt;br /&gt;   for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size-1;i++)&lt;br /&gt;   {&lt;br /&gt;       for(j=0;j&lt;b&gt;&lt;&lt;/b&gt;(size-1-i);j++)&lt;br /&gt;       {&lt;br /&gt;           if(a[j]&lt;b&gt;&gt;&lt;/b&gt;a[j+1])&lt;br /&gt;           {  &lt;br /&gt;               temp=a[j];&lt;br /&gt;               a[j]=a[j+1];&lt;br /&gt;               a[j+1]=temp;&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;   }  &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc,char *argv[])&lt;br /&gt;{&lt;br /&gt;   int size,*ar,i;  &lt;br /&gt;   printf(&quot;\nEnter the no of elements&quot;);&lt;br /&gt;   scanf(&quot;%d&quot;,&amp;size);&lt;br /&gt;   ar=(int *)malloc(size*sizeof(int));&lt;br /&gt;   printf(&quot;\nEnter the elements\n&quot;);&lt;br /&gt;   for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt;        scanf(&quot;%d&quot;,&amp;ar[i]);&lt;br /&gt;   bubble_sort(ar,size);&lt;br /&gt;   printf(&quot;\nThe Sorted List is :\n&quot;);&lt;br /&gt;   for(i=0;i&lt;b&gt;&lt;&lt;/b&gt;size;i++)&lt;br /&gt; printf(&quot;%d &quot;,ar[i]);&lt;br /&gt;   printf(&quot;\n&quot;);&lt;br /&gt;   return 0;&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/3209357320375937492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/3209357320375937492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/3209357320375937492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/3209357320375937492'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/implementation-of-bubble-sort.html' title='Implementation Of Bubble Sort'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2279790585312186476.post-6087543921395485385</id><published>2007-06-11T02:01:00.000+05:30</published><updated>2007-06-11T19:24:18.546+05:30</updated><title type='text'>Implementation Of Single Linked List</title><content type='html'>//Implementation of Single Linked List in C&lt;br /&gt;#include&lt;b&gt;&lt;&lt;/b&gt;stdio.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;#include&lt;b&gt;&lt;&lt;/b&gt;stdlib.h&lt;b&gt;&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;struct node&lt;br /&gt;{&lt;br /&gt;int data;&lt;br /&gt;struct node *next;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;void insert(struct node *ptr, int val)&lt;br /&gt;{&lt;br /&gt;struct node *new_node;&lt;br /&gt;new_node = (struct node*)malloc(sizeof(struct node));&lt;br /&gt;new_node-&gt;data = val;&lt;br /&gt;new_node-&gt;next =  ptr-&gt;next;&lt;br /&gt;ptr-&gt;next=new_node;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void delete(struct node *ptr)&lt;br /&gt;{&lt;br /&gt;struct node *p = ptr-&gt;next;&lt;br /&gt;ptr-&gt;next = p-&gt;next;&lt;br /&gt;free(p);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void display(struct node *head)&lt;br /&gt;{&lt;br /&gt;head=head-&gt;next;&lt;br /&gt;while(head!=NULL)&lt;br /&gt;{&lt;br /&gt;  printf(&quot;%d -&gt; &quot;,head-&gt;data);&lt;br /&gt;  head = head-&gt;next;&lt;br /&gt;}&lt;br /&gt;printf(&quot;NULL&quot;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main(int argc,char *argv[])&lt;br /&gt;{&lt;br /&gt;struct node p,*ptr,*save;&lt;br /&gt;int choice=1,value,pos;&lt;br /&gt;&lt;br /&gt;p.next=NULL;&lt;br /&gt;&lt;br /&gt;while(choice!=5)&lt;br /&gt;{&lt;br /&gt;  printf(&quot;\nMENU\n&quot;);&lt;br /&gt;  printf(&quot;1.Insert to Head\n&quot;);&lt;br /&gt;  printf(&quot;2.Insert in the Middle\n&quot;);&lt;br /&gt;  printf(&quot;3.Delete\n&quot;);&lt;br /&gt;  printf(&quot;4.Display\n&quot;);&lt;br /&gt;  printf(&quot;5.Quit\n&quot;);&lt;br /&gt;  scanf(&quot;%d&quot;,&amp;choice);&lt;br /&gt;  switch(choice)&lt;br /&gt;  {&lt;br /&gt;      case 1 : printf(&quot;\nEnter a number &quot;);&lt;br /&gt;                   scanf(&quot;%d&quot;,&amp;value);&lt;br /&gt;                   insert(&amp;p,value);&lt;br /&gt;                   break;&lt;br /&gt;      case 2 : printf(&quot;\nEnter a number &quot;);&lt;br /&gt;                   scanf(&quot;%d&quot;,&amp;value);&lt;br /&gt;                   printf(&quot;\nEnter the number after which to be inserted &quot;);&lt;br /&gt;                   scanf(&quot;%d&quot;,&amp;pos);&lt;br /&gt;                   ptr=p.next;&lt;br /&gt;                   while(ptr!=NULL)&lt;br /&gt;                   {&lt;br /&gt;                       if(ptr-&gt;data == pos)&lt;br /&gt;                       {&lt;br /&gt;                           insert(ptr,value);&lt;br /&gt;                           break;&lt;br /&gt;                       }&lt;br /&gt;                        ptr=ptr-&gt;next;&lt;br /&gt;                   }&lt;br /&gt;                   break;&lt;br /&gt;      case 3 : printf(&quot;\nEnter the number to be deleted &quot;);&lt;br /&gt;                   scanf(&quot;%d&quot;,&amp;pos);&lt;br /&gt;                   ptr=p.next;&lt;br /&gt;                   save=&amp;p;&lt;br /&gt;                   while(ptr!=NULL)&lt;br /&gt;                   {&lt;br /&gt;                       if(ptr-&gt;data == pos)&lt;br /&gt;                       {&lt;br /&gt;                           delete(save);&lt;br /&gt;                           break;&lt;br /&gt;                       }&lt;br /&gt;                       save=ptr;&lt;br /&gt;                       ptr=ptr-&gt;next;&lt;br /&gt;                   }&lt;br /&gt;                   break;&lt;br /&gt;      case 4 : display(&amp;p);&lt;br /&gt;                   break;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;return 0;&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://ds-algo.blogspot.com/feeds/6087543921395485385/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2279790585312186476/6087543921395485385' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/6087543921395485385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2279790585312186476/posts/default/6087543921395485385'/><link rel='alternate' type='text/html' href='http://ds-algo.blogspot.com/2007/06/implementation-of-linklist.html' title='Implementation Of Single Linked List'/><author><name>Vipul Agrawal</name><uri>http://www.blogger.com/profile/04724244051938012909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>