vs2017下 c語言 鍊錶的實現

2021-09-12 23:37:24 字數 3794 閱讀 4799

#include#include#include#pragma warning(disable:4996)

typedef struct node 

slist;

slist* slistcreate();//建立鍊錶

int slist_print(slist *phead);//遍歷鍊錶

int slist_nodeinsert(slist* phead,int x,int y);//插入值,在x之前插入y

int slist_nodedel(slist* phead,int y);//刪除值為y的節點

int slist_destory(slist* phead);//刪除鍊錶

slist* slistcreate()

phead->data = 0;

phead->next = null;

//1.不斷接受輸入malloc新節點

printf("\nplease enter you data:");

scanf("%d",&data);

pcurret = phead;

//輸入-1時退出

#include#include#include#pragma warning(disable:4996)

typedef struct node 

slist;

slist* slistcreate();//建立鍊錶

int slist_print(slist *phead);//遍歷鍊錶

int slist_nodeinsert(slist* phead,int x,int y);//插入值,在x之前插入y

int slist_nodedel(slist* phead,int y);//刪除值為y的節點

int slist_destory(slist* phead);//刪除鍊錶

slist* slistcreate()

phead->data = 0;

phead->next = null;

//1.不斷接受輸入malloc新節點

printf("\nplease enter you data:");

scanf("%d",&data);

pcurret = phead;

//輸入-1時退出

while (data != -1)

pm->data = data;

pm->next = null;

//2.新節點入鍊錶

pcurret->next = pm;

//3.新節點變成當前節點

pcurret = pm;//鍊錶尾部追加

printf("\nplease enter you data:");

scanf("%d", &data);

}return phead;

}int slist_print(slist *phead)

slist* pcurret = phead;

printf("\nbegin\t");

while (null != pcurret)

printf("end\t");

return 0;

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

pm->next = null;

pm->data = y;

//遍歷鍊錶

ppre = phead;

pcur = phead->next;

while (pcur != null)

ppre = pcur;

pcur = pcur->next;

}//新節點連線後節點

pm->next = ppre->next;

//前驅與新節點連線

ppre->next = pm;

return 0;

}int slist_nodedel(slist* phead, int y)

//遍歷鍊錶

while (pcur)

//移向下乙個節點

ppre = pcur;

pcur = pcur->next;

}//刪除節點

if (pcur==null)

//將前驅節點指向刪除後的下乙個節點

ppre->next = pcur->next;

free(pcur);

return 0;

}int slist_destory(slist** phead1)

slist* tmp = null;

//將二級指標變為一級指標

slist* phead = *phead1;

//釋放每乙個節點的記憶體

while (phead!=null)

//將頭指標置空,防止野指標

*phead1 = null;

return 0;

}void main()

while (data != -1)

pm->data = data;

pm->next = null;

//2.新節點入鍊錶

pcurret->next = pm;

//3.新節點變成當前節點

pcurret = pm;//鍊錶尾部追加

printf("\nplease enter you data:");

scanf("%d", &data);

}return phead;

}int slist_print(slist *phead)

slist* pcurret = phead;

printf("\nbegin\t");

while (null != pcurret)

printf("end\t");

return 0;

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

pm->next = null;

pm->data = y;

//遍歷鍊錶

ppre = phead;

pcur = phead->next;

while (pcur != null)

ppre = pcur;

pcur = pcur->next;

}//新節點連線後節點

pm->next = ppre->next;

//前驅與新節點連線

ppre->next = pm;

return 0;

}int slist_nodedel(slist* phead, int y)

//遍歷鍊錶

while (pcur)

//移向下乙個節點

ppre = pcur;

pcur = pcur->next;

}//刪除節點

if (pcur==null)

//將前驅節點指向刪除後的下乙個節點

ppre->next = pcur->next;

free(pcur);

return 0;

}int slist_destory(slist** phead1)

slist* tmp = null;

//將二級指標變為一級指標

slist* phead = *phead1;

//釋放每乙個節點的記憶體

while (phead!=null)

//將頭指標置空,防止野指標

*phead1 = null;

return 0;

}void main()

c語言單向鍊錶的實現

VS2017下Git的使用

1 找到專案的git位址 2 開啟 vs2017的團隊資源管理器面板,直接轉殖 複製 遠端github上的專案 3 追加新專案,到以上工程中。新建專案時,把專案建立在步驟二中轉殖的目錄裡。建立成功後每個檔案前都有乙個 的圖示。4 同步提交 點選右下角的專案名稱,這裡可以快速到專案列表,這裡檢視所有的...

VS2017開發C語言出現「no init

當你的編譯器出現這種錯誤時,只需要在winnt.h標頭檔案中 即可消除錯誤提示 補充一點 這一 塊是微軟工程師用於在舊版本的vs中消除該錯誤提示的預編譯頭 雖然微軟的工程師們宣稱他們在最新的vs2019tkuzu中已經修復了該程式設計客棧錯誤,但是仍有很多程式設計客棧人受到程式設計客棧了該錯誤的困擾...

C語言 VS2017不支援變長陣列

include 傳統方式和變長方式 void t trots double ar,int n void vla trots int n,double ar n vs不支援變長陣列 intmain void void t trots double ar,int n printf n void vla ...