資料結構 直接插入排序

2021-10-08 04:40:12 字數 1372 閱讀 1291

#include

#include

#include

#include

#include

#include

#define maxsize 100

#define elemtype int

#define status int

using namespace std;

//順序表資料結構

typedef

struct

sqlist;

status initlist

(sqlist &l)

//建立順序表函式 初始化前n個資料

bool creatlist

(sqlist &l,

int n)

return true;

}//插入函式 位置i插入資料 i及之後元素後移 1=bool insertlist

(sqlist &l,

int i,elemtype e)

if(l.length+

1>=maxsize)

//判斷儲存空間是否已滿

for(

int j=l.length+

1;j>=i;j--

) l.data[i]

=e; l.length++

;return true;

}int

locateelem

(sqlist l,elemtype e)

return0;

}void

printlist

(sqlist l)

printf

("\n");

}//建立順序表函式

void

create

(sqlist &l)

else

printf

("輸入長度非法!\n");

}void

insert

(sqlist &l)

}//查詢功能函式 呼叫locateelem查詢元素

void

search

(sqlist l)

else

printf

("未找到該元素!\n");

}//直接插入排序 公升序排序

void

insertsort

(sqlist &l)

l.data[j+1]

=l.data[0]

;//哨兵入列}}

printlist

(l);

}//選單

void

menu()

intmain()

}return0;

}

資料結構 直接插入排序

直接插入排序 include include typedef struct int elem int length sqlist void initsqlist sqlist l int i printf 請輸入元素個數 scanf d l length l elem int malloc size...

資料結構 直接插入排序

直接插入排序 將待插入子串行元素逐步插入到有序序列的執行過程。設有一待排序序列s 其中是有序的,是無序的,要把後面無需的元素,乙個乙個的插入到前面有序的集合中去。如下面的序列可以分為兩個子串行 和 初始序列 75 88 68 92 88 62 77 96 80 72 第一次排序 75 88 68 9...

資料結構 直接插入排序

將乙個記錄插入到已排好序的序列中,從而得到乙個新的有序序列 將序列的第乙個資料看成是乙個有序的子串行,然後從第二個記錄逐個向該有序的子串行進行有序的插入,直至整個序列有序 可以選擇不同的方法在已經排好序資料表中尋找插入位置。根據查詢方法不同,有多種插入排序方法,下面要介紹的是直接插入排序。設待排序的...