shellSort

#include<iostream>
#include<iomanip>
using namespace std;



#define MAX_ARY 15

void shellSort(int list[], int last);

int main()
{

 int ary[MAX_ARY]={12,12,23,54,67,43,67,87,56,4,3,2,54,67,9};


 cout << "before sort"<<endl;

 for(int i=0; i<MAX_ARY; i++)
 {
  cout<<setw(3)<<ary[i];
 }

 cout<<endl;

 cout<<"after sort"<<endl;

 shellSort(ary, MAX_ARY-1);

 for(int i=0; i<MAX_ARY; i++)
 {
  cout<<setw(3)<<ary[i];
 }
 cout<<endl;

}

void shellSort(int list[], int last)
{
 int hold;
 int incre;
 int curr;
 int walker;
 incre = last /2;
 int pass =1;

 while(incre != 0)
 {
  for(curr=incre; curr<=last; curr++)
  {
   hold = list[curr];
   walker = curr - incre;

   while(walker>=0 && hold < list[walker])
   {
    list[walker + incre] = list[walker];
    walker = walker - incre;
   }//while(walker>=0 && hold < list[walker])
   list[walker + incre] = hold;
  }//for
  //pass출력하기
  
  cout<<"PASS"<<pass++<<"("<<incre<<")"<<":";

  for(int i=0; i<MAX_ARY; i++)
  {
   cout<<setw(3)<<list[i];
  }
  cout<<endl;

  incre=incre/2;

 }//while(incre!=0)
 
}

 

 

'1. IT Story > Development' 카테고리의 다른 글

무료 IT 개발 언어공부, 코딩공부 유튜브 TOP5  (0) 2021.01.26
heapSort  (0) 2012.04.04
selectionSort  (0) 2012.04.04
오픈 API를 이용한 간단한 번역프로그램  (0) 2012.03.29
ChatClient  (0) 2012.03.29
MultiChatServer  (0) 2012.03.29
MultiChatClient  (0) 2012.03.29
큐를 이용한 간단한 구직Pro  (0) 2012.03.29
블로그 이미지

운명을바꾸는자

IT와 함께 살아가는 삶

,