鍊錶的基本操作實現 建立,增,刪,逆置)

2021-07-03 10:29:12 字數 1814 閱讀 8667

#define _crt_secure_no_warnings

#include#include#includetypedef struct node

slist;

//建立鍊錶

slist *create_slist(slist *phead);

int print_slist();

//在節點數值為x的前面插入y

int slist_nodeinsert(slist *phead, int x, int y);

//刪除節點y

int slist_nodedel(slist *phead, int y);

int slist_destory(slist *phead);

int slist_revse(slist *phead);

int slist_nodeinsert(slist *phead, int x, int y)

while (pcur)

ppior = pcur;

pcur = pcur->next;

} pnode->next = pcur;

ppior->next = pnode;

return ret;

}int print_slist(slist *phead)

pcur = phead->next;

printf("\nbegin\n");

while (pcur)

printf("\nend\n");

return ret;

}slist *create_slist()

phead->data = 0;

phead->next = null;

printf("please enter the data of node:(-1: quit)\n");

scanf("%d", &data);

//不斷的malloc節點

//不斷的讓新pm節點入鍊錶

//1、新節點入鍊錶(pcur -> next = pm)

//2、當前節點下移,pcur = pm

//我們需要不斷的記錄下來最後乙個節點的位置,pcur

pcur = phead;//準備環境,讓pcur指向phead

while (data != -1)

pm->data = data;

pm->next = null;

pcur->next = pm;

pcur = pm;

printf("please enter the data of node:(-1: quit)\n");

scanf("%d", &data);

} pcur->next = null;//可以 不用已經構件節點的時候已經複製了

return phead;

}int slist_nodedel(slist *phead, int y)

while (phead)

pprior = phead;

phead = phead->next;

} if (null == phead)

return ret;

}int slist_destory(slist *phead)

while (phead)

return ret;

}int slist_reseve(slist *phead)

p = phead->next;

//ptemp = p;

phead->next = null;

while (p) }

void main()

python 實現鍊錶的逆置

class node def init self,value,next self.value value self.next next class link def init self,head self.link create head deflink create self,head self....

鍊錶的逆置

5.鍊錶的逆置 已知head指向乙個帶頭節點的單向鍊錶,鍊錶中每個結點包含資料域和指標域。用鍊錶實現該鍊錶的逆置,並輸出。例如 輸入 5 整數表示要輸入的字元個數 abcde 輸出 edcba 注意 不允許通過改變每個節點的資料域來實現效果,必須改變鍊錶連線順序發生逆置。我寫的 如下 include...

鍊錶的逆置

剛剛除錯出來,趁熱寫一下。輸入多個整數,以 1作為結束標誌,順序建立乙個帶頭結點的單鏈表,之後對該單鏈表的資料進行逆置,並輸出逆置後的單鏈表資料。input 輸入多個整數,以 1作為結束標誌。output 輸出逆置後的單鏈表資料。sample input 12 56 4 6 55 15 33 62 ...