91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1.97MB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2023-09-08
  • 語言: C/C++
  • 標簽: 單鏈表??增刪改查??

資源簡介

VS2008運行環境 c語言實現單鏈表增刪改查操作 并輸出到控制臺上

資源截圖

代碼片段和文件信息

//?CNode.cpp?:?定義控制臺應用程序的入口點。
//

#include?“stdafx.h“
#include?“windows.h“

typedef?struct?_Node
{
char?data;
_Node?*next;
}Node;
void?insertNode(Node?**headint?ichar?e);
void?printNode(Node?**head);?
void?deleteNode(Node?**headint?i);?

int?_tmain(int?argc?_TCHAR*?argv[])
{
Node?*h;?????
h?=?NULL;?
insertNode(&h0‘a‘);?????
insertNode(&h1‘b‘);?????
insertNode(&h0‘c‘);?????
insertNode(&h4‘d‘);?????
printNode(&h);?????
deleteNode(&h1);?????
printNode(&h);?????
deleteNode(&h0);?????
printNode(&h);?????
deleteNode(&h1);?????
printNode(&h);?
return?0;
}
/*??*插入操作要確保要插入位置的前一個節點不為空并標記出其位置指針?
*因此要確保q的存在?
*節點從0計數?
第0個節點是頭指針所指節點?*/
void?insertNode(Node?**headint?ichar?e)
{???????
Node?*q;??
Node?*p;?????
int?j;??????
p?=?*head;???
if(i?==?0)?????
{
//插入位置在頭指針處?頭指針為空?不為空?時的情況?
if((p?=?(Node?*)malloc(sizeof(Node)))?==?NULL)???
{????????
//節點空間申請失敗??
}????????
p->next?=?*head;????
p->data?=?e;??????
*head?=?p;????????
printf(“%c\n“e);????
return;?????
}???????
q?=?*head;?
j?=?0;???
while(p?!=?NULL?&&?j? {?????????
q?=?p?;????
p?=?p->next;??
j++;????
}???????
if(i?==?j)?
{????????
if((p?=?(Node?*)malloc(sizeof(Node)))?==?NULL)
{????????????
//節點空間申請失敗
}??????
p->data?=?e;?
p->next?=?q->next;?//將新申請的節點next指向當時的操作節點?
q->next?=?p;?????//將原操作節點next指向新申請的節點???????
printf(“%c\n“e);???????
return;?????
}?????
//當?i?!=?j?時的情況輸出error?????
printf(“插入位置為%d的節點失敗?!\n“i);
}?
void?printNode(Node?**head)?
{?????
Node?*p?=?*head;????
if?(p?==?NULL)????
{????????
printf(“%s\n“NULL);
}????
while(p?!=?NULL)?????
{?????????
printf(“%c\n“p->data);??
p?=?p->next;??
}???????
}???
/*?
*刪除操作要求是?要刪除節點和其前一個節點都不可為空并標記其位置指針??
*因此要確保p?q都不為空?
*節點從0計數?
第0個節點是頭指針所指節點?*/?
void?deleteNode(Node?**?head??int?i?)?
{???????????
Node?*?q;//標識要刪除節點的前一個節點??
Node?*?p;//標識要刪除的節點????
int?j;??????????
if(*head?==?NULL)??
{?????????
//empety?node?list????????
printf(“刪除元素不存在!\n“);?
return;???
}???
p?=?*head;????
if(i?==?0)???
{????????
*head?=?p->next;?
free(p);??????
printf(“成功刪除位置為%d的元素!\n“i);
//p?=?NULL;????????
return?;?????
}???????
q?=?*head;??
j?=?0;???
while(p->next?!=?NULL?&&?j? {????????
q?=?p;???
p?=?p->next;???
j?++;????
}???????
if(i?==?j)????
{????????
q->next?=?p->next;?
free(p);???
printf(“成功刪除位置為%d的元素!\n“i);?
return;????
//p?=?NULL;??
}????
//當?i?!=?j?時的情況輸出error??
printf(“要刪除位置為%d的元素不存在!\n“i);??
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????2887??2012-09-21?18:11??CNode\CNode.cpp

?????文件????7695360??2012-09-21?18:11??CNode\CNode.ncb

?????文件????????875??2012-09-21?17:54??CNode\CNode.sln

????..A..H.?????11264??2012-09-21?18:11??CNode\CNode.suo

?????文件???????4492??2012-09-21?17:54??CNode\CNode.vcproj

?????文件???????1427??2012-09-21?18:11??CNode\CNode.vcproj.MICROSO-BJT4QU3.Administrator.user

?????文件???????1171??2012-09-21?17:54??CNode\ReadMe.txt

?????文件????????210??2012-09-21?17:54??CNode\stdafx.cpp

?????文件????????233??2012-09-21?17:54??CNode\stdafx.h

?????文件????????498??2012-09-21?17:54??CNode\targetver.h

?????目錄??????????0??2012-09-21?18:12??CNode

-----------?---------??----------?-----??----

??????????????7718417????????????????????11


評論

共有 條評論