Ejemplo n.º 1
0
int main(int argc, char **argv)
{
        int i, n;
	scanf("%d", &n);
	struct Elem *nil, *spis;
	nil = InitDoubleLinkedList();
	for(i = 0; i < n; i++) {
		spis = InitDoubleLinkedList();
		scanf("%d", &(spis->v));
		InsertAfter(nil, spis);
	}
	//printf("%d\n", (spis->next)->v);
	InsertSort(nil);
	spis = nil->next;
	struct Elem *help;
	for(i = 0; i < n; i++, spis = spis->next) {
		printf("%d ", spis->v);
		//printf("free %d\n ", (spis->prev)->v);
		if (i)
			free(spis->prev);
	}
        //printf("%d ", (spis->prev)->v);
	printf("\n");
        free(spis->prev);
	free(spis);
	return 0;
}
Ejemplo n.º 2
0
int main()
{
    SqList L;
    Creat_list(L);
    InsertSort(L);
    return 0;
}
Ejemplo n.º 3
0
void show_dispose(DIR*dir_ptr,char*dirname,int flag)
{
    int u=false;
    if(flag%U==0)
    u=true;
    DIR* dir_ptr2;
    dir_ptr2=opendir(dirname);
    if(flag%T==0 || flag % B ==0)
    {
        Node *head;
        head=Creat(dir_ptr2,dirname,u);
        if (flag % T ==0)
        {
            head=InsertSort(head);
        }
        if(flag % B == 0)
        {
            head=Reverse(head);
        }
        show_sort(head,flag);
    }
    else
    show(dir_ptr2,dirname,flag);
    closedir(dir_ptr2);

}
Ejemplo n.º 4
0
/*---------------TEST DRIVER----------------*/
int main(){
 	struct node* head = BuildOneTwoThree();
	PrintList(head);
	InsertSort(&head);
	PrintList(head);
    return 0;
}
Ejemplo n.º 5
0
void TestInsertSort()
{
	int arr[] = { 2, 5, 4, 9, 3, 6, 8, 7, 1 ,0};
	int len = sizeof(arr) / sizeof(arr[0]);
	InsertSort(arr, len);
	PrintArrray(arr, len);
}
Ejemplo n.º 6
0
int main(int argc, char *argv[]){
	FILE *fp;
	int *array, num, flag;

	num = atoi(argv[2]);
	flag = atoi(argv[3]);
	array = (int *)malloc(sizeof(int) * num);
	if((fp = fopen(argv[1], "rb")) == NULL){
		fprintf(stderr, "Cant open file\n");
		exit(1);
	}
	fread(array, sizeof(int), num, fp);
	fclose(fp);
	switch(flag){
		case 1:
			SelectSort(array, num);
			break;
		case 2:
			InsertSort(array, num);
			break;
		default:
			fprintf(stderr, "Wrong Flag(%d)!! \n", flag);
			exit(1);
	}
	free(array);

	return dTrue;
}
Ejemplo n.º 7
0
int main()
{
    int pole1[10] = {7, 1, 2, 0, 8, 4, 5, 3, 9, 6};
    int pole2[10] = {0, 3, 1, 8, 7, 2, 5, 4, 6, 9};
    int pole3[10] = {2, 1, 3, 6, 9, 0, 4, 5, 7, 8};
    
    printf("Původní pole1: ");
    VypisPole(pole1, 10);
    InsertSort(pole1, 10);
    printf("\nSetřízené pole1 (InsertSort): ");
    VypisPole(pole1, 10);
    
    printf("\nPůvodní pole2: ");
    VypisPole(pole2, 10);
    BubbleSort(pole2, 10);
    printf("\nSetřízené pole2 (BubbleSort): ");
    VypisPole(pole2, 10);
    
    printf("\nPůvodní pole3: ");
    VypisPole(pole3, 10);
    SelectSort(pole3, 10);
    printf("\nSetřízené pole3 (SelectSort): ");
    VypisPole(pole3, 10);
    
    return 0;
}
Ejemplo n.º 8
0
void forA::dataOutput() {
	total=0;
		
		InsertSort(&cow[0], cow.size());
			for (int i = 0; i <= 4; i++)
						total += cow[i];
				cout << total << endl;
}
int ConcatenateDiffBlocks(DiffBlock *head, unsigned int* block_n, int block_num)
{
    CreateList(&head, block_n, block_num);
    ConcatenateNodes_x(&head);
    //AscendingSortList(head);
    InsertSort(&head);
    ConcatenateNodes_y(&head);
    return ListConvertToArray(head, block_n);
}
Ejemplo n.º 10
0
void QuickSort(int a[], int left, int right)
{
	if(right-left < M_LEN ) {
		InsertSort(a, left, right);
	}
	int pivotPos = Partition(a, left, right);
	QuickSort(a, left, pivotPos-1);
	QuickSort(a, pivotPos+1, right);
}
Ejemplo n.º 11
0
int main(int argc, char* argv[])
{
  std::vector<int> v = {-1,5,-9,3,-3,4,4,2,1};
  Print(BubbleSort(v));
  Print(InsertSort(v));
  Print(SelectionSort(v));
  std::cout << "--------------" << std::endl;
  return EXIT_SUCCESS;
}
Ejemplo n.º 12
0
int main()
{
   int array[] = {10,9,8,7,6,5,4,3,2,1};
   int len = sizeof(array) / sizeof(int);
   PrintArray(array,len,"直接插入排序前:");
   InsertSort(array,len);
   PrintArray(array,len,"直接插入排序后:");
   return 0;
}
Ejemplo n.º 13
0
void TestInsertSort()
{
	int array[] = {2,5,6,9,1,3,4,7,8,0};
	InsertSort(array,sizeof(array)/sizeof(array[0]));
	for(int i = 0; i<sizeof(array)/sizeof(array[0]); i++)
	{
		cout<<array[i] <<" " ;
	}
	cout <<endl;
}
Ejemplo n.º 14
0
int main()
{
	int nArray[] = {10,3,5,2,1,4};
	int nSize = sizeof(nArray)/sizeof(nArray[0]);
	printArray(nArray, nSize);
	InsertSort(nArray, nSize);
	printArray(nArray, nSize);
	getchar();
	return 0;
}
Ejemplo n.º 15
0
void InsertSortTest()
{
    int arr[] = {9,1,5,8,3,7,4,6,2};
    int length = sizeof(arr)/sizeof(arr[0]);
    printf("Befor sort:\n");
    PrintArr(arr, length);

    InsertSort(arr, length);
    printf("After sort:\n");
    PrintArr(arr, length);
}
Ejemplo n.º 16
0
int main(){
    clock_t start,end;
    printSortArray(a,0);
    start=clock();
    InsertSort(a);
    end=clock();
    printSortArray(a,10);
    double duration=(double)(end-start)/CLOCKS_PER_SEC;
    printf("排序使用时间:%f\n",duration);
    return 0;
}
Ejemplo n.º 17
0
Archivo: main.c Proyecto: shmily/linux
int main( void )
{
	char str[100] = {0};
	
	scanf("%s", str);

	InsertSort(str, strlen(str));

	printf("%s",str);
    return 0;
}
Ejemplo n.º 18
0
Archivo: main.c Proyecto: shmily/linux
int main( void )
{
    char str[1025];

    memset(str, 0, 1025);
    scanf("%s", str);

    InsertSort(str, strlen(str));

    printf("%s",str);
    return 0;
}
Ejemplo n.º 19
0
void ShellSort(int iData[], int iValue)
{
	int k = iValue;
	while(k>1)
	{
		k = k / 2;
		for (int j = 0;j < k;j++)
		{
			InsertSort(iData, iValue, j, k);
		}
	}
}
Ejemplo n.º 20
0
int main()
{
    int i, a[]={5,2,6,0,3,9,1,7,4,8};
    int len=sizeof(a)/sizeof(int);
    InsertSort(a, len);
    printf("排序后的结果是:\n");
    for(i=0; i<len; i++)
    {
        printf("%d ", a[i]);
    }
    printf("\n\n");
}
Ejemplo n.º 21
0
int main()
{
    int loop = 0;
    char array[N] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};  /*the worst situation*/
    InsertSort(array, N);
    
    for (; loop < N; ++ loop)
    {
        printf("%d,", array[loop]);
    }
    printf("\n");
    return 0;
}
Ejemplo n.º 22
0
int main(int argc, char const *argv[])
{
	int a[8] = {4,54,2,65,34,75,23,12};

	InsertSort(a,8);
	int i;
	for(i = 0; i < 8; i++)
	{
		printf("%d | ", a[i]);
	}
	printf(" \n");

	return 0;
}
Ejemplo n.º 23
0
int main()
{
    char a[120],b[120];
    int A[28]={0},B[28]={0};
    int a1,b1,i;
    scanf("%s%s",a,b);
    a1=strlen(a);
    b1=strlen(b);
    for(int i=0;i<a1;i++)
        A[a[i]-'A'+1]++;
    for(int i=0;i<b1;i++)
        B[b[i]-'A'+1]++;
    InsertSort(A,26);
    InsertSort(B,26);
    for(i=1;i<27;i++)
        if(A[i]!=B[i])
        {
             printf("NO\n");
             break;
        }
    if(i==27)printf("YES\n");
    system("pause");
    return 0;
}
Ejemplo n.º 24
0
 bool IsContinuous(vector<int> numbers ) {
     if (numbers.size() == 0)
         return false;
     InsertSort(numbers);
     int diff = 0, size = numbers.size(), i, ksum;
     for (i = 0;i < size && numbers[i] == 0; ++i);
     ksum = i;
     for (i = i + 1;i < size; ++i) {
         if (numbers[i] == numbers[i - 1])
             return false;
         diff += numbers[i] - numbers[i - 1] - 1;
     }
     std::cout << diff << " " << ksum << std::endl;
     return diff <= ksum;
 }
int main()
{
	int *vetor[max_tam_vetor];
	int i,escolha;

	clock_t start, end;
	double cpu_time_used;

	escolha=escolhaVetor();

	printf("\n");

	inicializaVetor(vetor,escolha);
	printf("\nOrdenação\tTempo\n");
	
	start = clock();
	InsertSort(vetor,max_tam_vetor);
	end = clock();
	cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
	printf("InsertSort\t%.10f\n",cpu_time_used);

	inicializaVetor(vetor,escolha);

	start = clock();
	BubbleSort(vetor,max_tam_vetor);
	end = clock();
	cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
	printf("BubbleSort\t%.10f\n",cpu_time_used);

	inicializaVetor(vetor,escolha);

	start = clock();
	QuickSort(vetor,0,max_tam_vetor-1);
	end = clock();
	cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
	printf("QuickSort\t%.10f\n",cpu_time_used);

	inicializaVetor(vetor,escolha);

	start = clock();
	MergeSort(vetor,max_tam_vetor);
	end = clock();
	cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
	printf("MergeSort\t%.10f",cpu_time_used);

	printf("\n\n");
	
}
int main(void)
{
    int n;
    int Unsorted1[MAX], Unsorted2[MAX], Unfinished[MAX];

    scanf("%d", &n);
    for (int i = 0; i < n; ++i){
        scanf("%d", &Unsorted1[i]);
        Unsorted2[i] = Unsorted1[i];
    }
    for (int i = 0; i < n; ++i)
        scanf("%d", &Unfinished[i]);
    HeapSort(Unsorted1, n, Unfinished);
    InsertSort(Unsorted2, n, Unfinished);
    return 0;
}
Ejemplo n.º 27
0
int main() {
  int array[5];
  int p;
  Post(array, &p);
  system("clear");
  printf("----------------------------");
  printf("\n");
  Print(array);
  printf("\n");
  InsertSort(array, p);
  Print(array);
  printf("\n");
  printf("----------------------------");
  printf("\n");
  return 0;
}
Ejemplo n.º 28
0
void QSort(SqList *L, int low, int high)
{
	int pivot;

	if((high-low)>MAX_LENGTH_INSERT_SORT)
	{
		while(low<high)
		{
			pivot = Partition(L, low, high);
			QSort(L, low, pivot-1);				//对低子表递归排序
			low = pivot + 1;					//尾递归
		}
	}
	else
		InsertSort(L);
}
Ejemplo n.º 29
0
int main() {
   int fd, data;

   fd = open("temp.txt", O_CREAT|O_RDWR|O_TRUNC, 0600);
   while (EOF != scanf("%d", &data))
      write(fd, &data, sizeof(int));

   InsertSort(fd);

   lseek(fd, 0, SEEK_SET);
   while (0 != read(fd, &data, sizeof(int)))
      printf("%d ", data);
   printf("\n");

   return 0;
}
Ejemplo n.º 30
0
int main()
{
	srand((unsigned)time(NULL));   //使用系统时间设置随机数种子
	int i;
	int A[COUNT];
	for (i = 0; i < COUNT; i++)
		A[i] = rand() % 100;       //产生COUNT个0~99的随机数

	printf("before sort......\n");
	print(A);

	InsertSort(A, COUNT);

	printf("after sort......\n");
	print(A);

}