From 0a03411446a8accf4b8c6b9f2c4002955f48d726 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 10 Jun 2022 00:55:54 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'ex8=5F1.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ex8_1.c | 215 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 107 insertions(+), 108 deletions(-) diff --git a/ex8_1.c b/ex8_1.c index a66edab..bc84c77 100644 --- a/ex8_1.c +++ b/ex8_1.c @@ -1,108 +1,107 @@ -#include -#include -#include -#define MAX 100 -typedef int DataType; -typedef struct list{ - int data[MAX]; - int start; - int length; -}List; -/* - 直接插入排序 -*/ -void DirectSort(List *L){ - int j; - for(int i = 2; i<=L->length; i++){ - L->data[0] = L->data[i]; - j = i-1; - while(L->data[0] < L->data[j]){ - L->data[j+1] = L->data[j]; - j = j-1; - } - L->data[j+1] = L->data[0]; - } -} -/* - 快速排序 -*/ -void QuickSort(List *L, int first, int end){ - int i = first, j = end, temp = L->data[i]; - while(i < j){ - while(i < j && temp <= L->data[j]){ - j--; - } - L->data[i] = L->data[j]; - while(i < j && L->data[i] <= temp){ - i++; - } - L->data[j] = L->data[i]; - } - L->data[i] = temp; - if(first < i-1){ - QuickSort(L, first, i-1); - } - if(i+1 < end){ - QuickSort(L, i+1, end); - } -} -/* - 输入数组元素 -*/ -void input(List *L){ - printf("请输入线性表长度:"); - scanf("%d", &L->length); - for(int i=L->start; istart + L->length; i++){ - printf("请输入第 %d 个元素:", i + 1 - L->start); - scanf("%d", &L->data[i]); - } -} -/* - 输出数组元素 -*/ -void output(List L){ - printf("数组元素为:\n"); - for(int i=L.start; i +#include +#include +#define MAX 100 +typedef int DataType; +typedef struct list{ + DataType data[MAX]; + int start; + int length; +}List; +/* + 直接插入排序 +*/ +void DirectSort(List *L){ + int j; + for(int i = 2; i <= L->length; i++){ + L->data[0] = L->data[i]; + j = i-1; + while(L->data[0] < L->data[j]){ + L->data[j+1] = L->data[j]; + j = j-1; + } + L->data[j+1] = L->data[0]; + } +} +/* + 快速排序 +*/ +void QuickSort(List *L, int first, int end){ + int i = first, j = end, temp = L->data[i]; + while(i < j){ + while(i < j && temp <= L->data[j]){ + j--; + } + L->data[i] = L->data[j]; + while(i < j && L->data[i] <= temp){ + i++; + } + L->data[j] = L->data[i]; + } + L->data[i] = temp; + if(first < i-1){ + QuickSort(L, first, i-1); + } + if(i+1 < end){ + QuickSort(L, i+1, end); + } +} +/* + 输入数组元素 +*/ +void input(List *L){ + printf("请输入线性表长度:"); + scanf("%d", &L->length); + for(int i=L->start; istart + L->length; i++){ + printf("请输入第 %d 个元素:", i + 1 - L->start); + scanf("%d", &L->data[i]); + } +} +/* + 输出数组元素 +*/ +void output(List L){ + printf("数组元素为:\n"); + for(int i=L.start; i