PTA資料結構習題(浙江大學)

2021-10-04 13:40:18 字數 3298 閱讀 7653

感謝疫情期間pta開放免費練習,趁著這個機會補一下資料結構的代

#include

#include

#include

struct stud_node

;struct stud_node *

createlist()

;struct stud_node *

deletelist

(struct stud_node *head,

int min_score)

;int

main()

/* 你的**將被嵌在這裡 */

struct stud_node *

createlist()

return phead;

}struct stud_node *

deletelist

(struct stud_node *head,

int min_score)

// 不是頭結點

else

free

(tobedeleted);}

else

}return head;

}

#include

#include

#define maxsize 10

#define notfound 0

typedef

int elementtype;

typedef

int position;

typedef

struct lnode *list;

struct lnode

;list readinput()

;/* 裁判實現,細節不表。元素從下標1開始儲存 */

position binarysearch

(list l, elementtype x)

;int

main()

/* 你的**將被嵌在這裡 */

position binarysearch

(list l, elementtype x)

return notfound;

}

#include

#include

#define maxsize 10

typedef

enum

bool;

typedef

int elementtype;

typedef

int position;

typedef

struct lnode *list;

struct lnode

;list readinput()

;/* 裁判實現,細節不表。元素從下標0開始儲存 */

void

printlist

(list l)

;/* 裁判實現,細節不表 */

bool insert

(list l, elementtype x)

;int

main()

/* 你的**將被嵌在這裡 */

bool insert

(list l, elementtype x)

else

if(x > l->data[left]

)else

else

if(x < l->data[mid])}

insertelement

(l, mid +

1, x)

;return true;}}

void

insertelement

(list l,

int index, elementtype x)

else

l->data[index]

= x;

l->last +=1

;}}

#include

#include

typedef

int elementtype;

typedef

struct node *ptrtonode;

struct node

;typedef ptrtonode list;

list read()

;/* 細節在此不表 */

void

print

( list l )

;/* 細節在此不表 */

list insert

( list l, elementtype x )

;int

main()

/* 你的**將被嵌在這裡 */

list insert

( list l, elementtype x )

// 兩個指標用於尋找插入位置

list pre = head;

list node = l->next;

while

(x > node->data)

} pnew->next = node;

pre->next = pnew;

return head;

}

#include

#include

typedef

int elementtype;

typedef

struct node *ptrtonode;

struct node

;typedef ptrtonode list;

list read()

;/* 細節在此不表 */

void

print

(list l)

;/* 細節在此不表;空煉表將輸出null */

list merge

(list l1, list l2)

;int

main()

list read()

return l;

}list merge

(list l1, list l2)

else

}// l2結束,l1還未結束

if(p1)

// l1結束,l2還未結束

if(p2)

l1->next =

null

; l2->next =

null

;return head;

}void

print

(list l)

puts(""

);}else

}

浙江大學 資料結構 堆的操作

題目 05 樹7 堆中的路徑 25分 將一系列給定數字插入乙個初始為空的小頂堆h。隨後對任意給定的下標i,列印從h i 到根結點的路徑。每組測試第1行包含2個正整數nn n和mm m 1000 le 1000 1 000 分別是插入元素的個數 以及需要列印的路徑條數。下一行給出區間 10000,10...

資料結構mooc浙江大學附帶習題第一課

中國大學mooc 陳越 何欽銘 資料結構 2021春 這道題要理解的地方就是 符號的使用,以及結構體型別的定義和指向結構體型別資料的指標。之後的演算法就不算難的隨便看一看吧 include include define maxsize 10 define notfound 0 typedef int...

慕課學習筆記 資料結構 浙江大學

相比用迴圈函式,遞迴函式會占用較多的空間 解決問題方法的效率跟空間的利用效率有關 需要同時儲存遞迴呼叫的所有函式,直到呼叫到結束,才釋放儲存空間。計算多項式時,利用結合律f x a 0 x a 1 x a n 1 x a n 秦九韶演算法 所需時間比階乘演算法少,加減法比乘除法快很多。抽象資料型別 ...