資源簡介
有關與線性表的一些基本操作自己學習剛剛寫好的~.~(如有不足歡迎補充)

代碼片段和文件信息
//?ConsoleApplication3.cpp:?定義控制臺應用程序的入口點。
#include?“stdafx.h“
#include?
#include?
#include??
typedef?struct?lnode?{
int?data;
struct?lnode?*next;
}lnode*pnode;
void?destoryList(pnode?list)
{
pnode?p?tmp;
p?=?list->next;
list->next?=?NULL;
while(p->next==NULL)
{?
tmp?=?p->next;
free(p);
p?=?tmp;
}
printf(“鏈表銷毀完成\n“);
}
void?clearList(pnode?list)
{
pnode?p=list;
while?(p->next?!=?NULL)
{
p->data?=?0;
p?=?p->next;
}
printf(“鏈表清空完成\n“);
}
int?Listempty(pnode?list)
{
pnode?p?=?list->next;
while?(p->next?!=?NULL)
{
if?(p->data?!=?0)return?1;
p?=?p->next;
}
return?0;
}
int?Listlength(pnode?list)
{
int?n=0;
pnode?p?=?list->next;
while?(p->next?!=?NULL)
{
n++;
p?=?p->next;
}
return?n;
}
void?initlist(pnode?hnode)
{
int?data?=?1;
?hnode?=?(pnode)malloc(sizeof(lnode));
pnode?tlist?=?(pnode)malloc(sizeof(lnode));
if?(tlist?==?NULL)?{?printf(“節點創建失敗。“);?exit(1);}
hnode->data?=?NULL;
hnode->next?=?tlist;
printf(“請輸入鏈表數值:“);
while?(data?!=?0)
{
scanf_s(“%d“?&data);
if?(data?==?0)break;
pnode?list?=?(pnode)malloc(sizeof(lnode));
if?(list?==?NULL)?{?printf(“節點創建失敗。“);?exit(1);?}
list->next?=?NULL;
tlist->data?=?data;
tlist->next?=?list;
tlist?=?list;
}
}
void?printf_list(pnode?List)
{
pnode?prlist?=?List->next;
if?(prlist?!=?NULL)
{
while?(prlist->next?!=?NULL)
{
printf(“%d?“?prlist->data);
prlist?=?prlist->next;
}
}
printf(“\n“);
}
void?getelem(pnode?list?int?i?int?*e)
{
int?a=0b=0;
pnode?flist?=?list;
for?(b?=?0;?b? {
flist?=?flist->next;
}
*e?=?flist->data;
}
void?priorelem(pnode?list?int?cur_e?int?*pre_e)
{
pnode?nlist?=?list->next;
int?e;
while?(nlist?!=?NULL?&&?cur_e!=nlist->data)
{
e?=?nlist->data;
nlist?=?nlist->next;
if?(cur_e?==?nlist->data)
{
*pre_e?=?e;
}
}
}
void?nextelem(pnode?list?int?cur_e?int?*next_e)
{
pnode?nlist?=?list->next;
int?a=0;
while?(nlist?!=?NULL?&&?cur_e?!=?a)
{
nlist?=?nlist->next;
a?=?nlist->data;
if?(cur_e?==?nlist->data)
{
nlist?=?nlist->next;
*next_e?=?nlist->data;
}
}
}
void?listdelete(pnode?list?int?i?int?*e)
{
int?a;
pnode?nlist?=?list;
pnode?slist?=?list;
for?(a?=?0;?a? {
slist?=?nlist;
nlist?=?nlist->next;
}
slist->next?=?nlist->next;
*e?=?nlist->data;
nlist->data?=?NULL;
nlist->next?=?NULL;
free(nlist);
}
void?listinsert(pnode?list?int?i?int?e)
{
int?a;
pnode?nlist?=?list;
for?(a?=?0;?a? {
nlist?=?nlist->next;
}
pnode?slist?=?(pnode)malloc(sizeof(pnode));
slist->data?=?e;
slist->next?=?nlist->next;
nlist->next?=?slist;
}
int?main()
{
int?*b=(int?*)malloc(sizeof(int));
pnode?a?=?NULL;
initlist(a);
listdelete(a?2?b);
printf_list(a);
system(“pause“);
return?0;
}
/* char?str1[20]?=?{?“Hello?“?}?str2[20]?=?{?“Wor
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????49152??2018-05-13?19:22??單鏈表\.vs\ConsoleApplication3\v15\.suo
?????文件???36208640??2018-05-13?18:28??單鏈表\.vs\ConsoleApplication3\v15\Browse.VC.db
????..A..H.????????44??2018-05-13?18:52??單鏈表\.vs\ConsoleApplication3\v15\Browse.VC.opendb
?????文件????3604480??2018-05-13?13:14??單鏈表\.vs\ConsoleApplication3\v15\ipch\6917d9db3f9e7b5b.ipch
?????文件????3997696??2018-05-13?14:10??單鏈表\.vs\ConsoleApplication3\v15\ipch\AutoPCH\a2aa584aef1d1ae\EXE_COMMON.ipch
?????文件????3604480??2018-05-13?19:19??單鏈表\.vs\ConsoleApplication3\v15\ipch\f5c5a6f7baa9b8cb.ipch
?????文件???????7282??2018-05-13?19:18??單鏈表\ConsoleApplication3\ConsoleApplication3.cpp
?????文件???????8235??2018-05-13?19:19??單鏈表\ConsoleApplication3\ConsoleApplication3.vcxproj
?????文件???????1260??2018-05-13?19:19??單鏈表\ConsoleApplication3\ConsoleApplication3.vcxproj.filters
?????文件???????4704??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\ConsoleA.2CE8524E.tlog\CL.command.1.tlog
?????文件???????8220??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\ConsoleA.2CE8524E.tlog\CL.read.1.tlog
?????文件???????1976??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\ConsoleA.2CE8524E.tlog\CL.write.1.tlog
?????文件????????224??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\ConsoleA.2CE8524E.tlog\ConsoleApplication3.lastbuildstate
?????文件???????1628??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\ConsoleA.2CE8524E.tlog\li
?????文件???????3562??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\ConsoleA.2CE8524E.tlog\li
?????文件????????856??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\ConsoleA.2CE8524E.tlog\li
?????文件????????143??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\ConsoleApplication3.log
?????文件??????21892??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\ConsoleApplication3.obj
?????文件????2883584??2018-05-10?21:03??單鏈表\ConsoleApplication3\Debug\ConsoleApplication3.pch
?????文件??????38501??2018-05-13?16:31??單鏈表\ConsoleApplication3\Debug\list.obj
?????文件???????6027??2018-05-10?21:03??單鏈表\ConsoleApplication3\Debug\stdafx.obj
?????文件?????781312??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\vc141.idb
?????文件?????184320??2018-05-13?19:19??單鏈表\ConsoleApplication3\Debug\vc141.pdb
?????文件???????1954??2018-05-13?13:14??單鏈表\ConsoleApplication3\Release\ConsoleA.2CE8524E.tlog\CL.command.1.tlog
?????文件??????28398??2018-05-13?13:14??單鏈表\ConsoleApplication3\Release\ConsoleA.2CE8524E.tlog\CL.read.1.tlog
?????文件???????1294??2018-05-13?13:14??單鏈表\ConsoleApplication3\Release\ConsoleA.2CE8524E.tlog\CL.write.1.tlog
?????文件????????226??2018-05-13?13:14??單鏈表\ConsoleApplication3\Release\ConsoleA.2CE8524E.tlog\ConsoleApplication3.lastbuildstate
?????文件??????16962??2018-05-13?13:14??單鏈表\ConsoleApplication3\Release\ConsoleA.2CE8524E.tlog\ConsoleApplication3.write.1u.tlog
?????文件???????1734??2018-05-13?13:14??單鏈表\ConsoleApplication3\Release\ConsoleA.2CE8524E.tlog\li
?????文件???????4424??2018-05-13?13:14??單鏈表\ConsoleApplication3\Release\ConsoleA.2CE8524E.tlog\li
............此處省略34個文件信息
- 上一篇:Qt4鬧鐘
- 下一篇:架構師之路 PDF版
評論
共有 條評論