Posted by : Naveen's Blogs Tuesday, 29 April 2014

   #include< iostream.h > 
    #include< constream.h > 
    void read(int a[10],int n) 
    { 
      cout << "reading\n"; 
      for(int i=0;i < n;i++) 
        cin >> a[i]; 
    } 
    void display(int a[10],int n) 
    { 
      for(int i=0;i < n;i++) 
        cout << a[i] <<"\t"; 
    } 
    void shellsort(int a[10],int n) 
    { 
      int gap=n/2; 
      do 
      { 
        int swap; 
        do 
        { 
          swap=0; 
          for(int i=0;i < n-gap;i++) 
          if(a[i] > a[i+gap]) 
          { 
            int t=a[i]; 
            a[i]=a[i+gap]; 
            a[i+gap]=t; 
            swap=1; 
          } 
        } 
        while(swap); 
      } 
      while(gap=gap/2); 
    } 
    void main() 
    { 
      int a[10]; 
      int n; 
      clrscr(); 
      cout<<"enter n\n"; 
      cin>>n; 
      read(a,n); 
      cout<<"before sorting\n"; 
      display(a,n); 
      shellsort(a,n); 
      cout<<"\nafter sorting\n"; 
      display(a,n); 
      getch(); 
    }

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Popular Post

Blogger templates

Powered by Blogger.

- Copyright © Data Structures using C++ -Robotic- Powered by Blogger - Designed by NAVEEN KUMAR -

6