1
#include <iostream>
#define ELEMENTS 10
using namespace std;
void insertion_sort(char x[],int length)
{
int key,i;
for(int j=1;j<length;j++)
{
key=x[j];
i=j-1;
while(x[i]>key && i>=0)
{
x[i+1]=x[i];
i--;
}
x[i+1]=key;
}
}
int main()
{
char A[ELEMENTS]={'G','F','V','T','K','J','L','M','N','B'};
int x;
cout<<"NON SORTED LIST:"<<endl;
for(x=0;x<ELEMENTS;x++)
{
cout<<A[x]<<endl;
}
insertion_sort(A,ELEMENTS);
cout<<endl<<"SORTED LIST"<<endl;
for(x=0;x<ELEMENTS;x++)
{
cout<<A[x]<<endl;
}
return 0;
}
界貼
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.17.167
推
11/19 20:08, , 1F
11/19 20:08, 1F
推
11/19 22:53, , 2F
11/19 22:53, 2F
→
11/19 23:19, , 3F
11/19 23:19, 3F
推
11/21 17:42, , 4F
11/21 17:42, 4F
推
11/21 17:47, , 5F
11/21 17:47, 5F