Добавил:
Hist
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Программы c++ (сортировка, хэширование) / 2 / Binary_Insertion
.cpp//6. Сортировка двойной вставкой (необменная)
#include <iostream>
#include <string.h>
#define n 20
#define MaxLength 100
using namespace std;
int main(void)
{
char st[n][MaxLength],x[MaxLength];
int i,j,m,l,r;
strcpy(st[0],"dg");
strcpy(st[1],"dfg");
strcpy(st[2],"dfgd");
strcpy(st[3],"xbgf");
strcpy(st[4],"rd");
strcpy(st[5],"gfng");
strcpy(st[6],"zd");
strcpy(st[7],"gfd");
strcpy(st[8],"mhg");
strcpy(st[9],"lulo");
strcpy(st[10],"re");
strcpy(st[11],"sfd");
strcpy(st[12],"zsc");
strcpy(st[13],"dbfd");
strcpy(st[14],"vbnv");
strcpy(st[15],"reyg");
strcpy(st[16],"ergtw");
strcpy(st[17],"rgtewrg");
strcpy(st[18],";o;i");
strcpy(st[19],"3453");
for (i=0; i<n; i++)
{
strcpy(x,st[i]);
l=0; r=i;
while (l<r)
{
m=(l+r)/2;
if (st[m]>=x) {l=m+1;}
if (strcmp(st[m],x)>0) {l=m+1;}
else r=m;
}
for (j=i; j>r+1; j--)
{
strcpy(st[j],st[j-1]);
strcpy(st[r],x);
}
}
for (i=0; i<n; i++) {cout<<st[i]<<endl;}
//system("pause");
}
Соседние файлы в папке 2