YTU 2217 鍊錶查詢(線性表)

2021-09-17 02:47:42 字數 1803 閱讀 6533

本題只需要提交填寫部分的**

已知非空線性鍊錶由list指出,鏈結點的構造為(data,link).請寫一演算法,將鍊錶中資料域值最小的那個鏈結點移到鍊錶的最前面。要求:不得額外申請新的鏈結點

**:#include

using namespace std;

struct list

;struct list *listcreate(struct list *head,int n)    //建立鍊錶

previous->link=null;        //置表尾結束標誌

return head;                //返回首結點指標

}struct list *minmovefirst(struct list *head)    //將最小結點移至表尾

previous=current;        //記錄前驅結點

current=current->link;    //當前結點後移

}//此時的previous指向表尾

/************從鍊錶摘下最小結點*****************/

if(minnode==head)    //最小結點是首結點

head=head->link;    //首結點後移

else

previousminnode->link=minnode->link;

/************將最小結點放在表頭*****************/

minnode->link = head;

head = minnode;

return head;

}void listoutput(struct list *head)

}int main()

輸入長度n:6

輸入資料:4 2 6 88 34 6

2 4 6 88 34 6

copy

5

11 6 8 7 9

6 11 8 7 9
#include using namespace std;

struct list

;struct list *listcreate(struct list *head,int n) //建立鍊錶

previous->link=null; //置表尾結束標誌

return head; //返回首結點指標

}struct list *minmovefirst(struct list *head) //將最小結點移至表尾

previous=current; //記錄前驅結點

current=current->link; //當前結點後移

}//此時的previous指向表尾

/************從鍊錶摘下最小結點*****************/

if(minnode==head) //最小結點是首結點

head=head->link; //首結點後移

else

previousminnode->link=minnode->link;

/************將最小結點放在表頭*****************/

minnode->link = head;

head = minnode;

return head;

}void listoutput(struct list *head)

}int main()

YTU 2209 建立鍊錶 線性表

時間限制 1 sec 記憶體限制 128 mb 提交 282 解決 185 線性表 設鍵盤輸入n個英語單詞,輸入格式為n,w1,w2,wn,其中n表示隨後輸入英語單詞個數,試編一程式,建立乙個單向鍊錶,實現 如果單詞重複出現,則只在鍊錶上保留乙個。4 now come now please now ...

線性表 鍊錶

線性表的adt list.h 線性表的c 抽象類宣告 templateclass list 單鏈表節點的定義 link.h 單鏈表節點類的定義 template class link link link nextval null 鍊錶的實現宣告 成員函式的是實現 鍊錶的實現宣告 include st...

線性表 鍊錶

include include typedef int elemtype typedef struct node lnode,linklist linklist createlinklist1 頭插法 linklist createlinklist2 尾插法 void lengthlinklist ...