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

  • 大小: 3.40KB
    文件類型: .c
    金幣: 1
    下載: 0 次
    發布日期: 2024-04-15
  • 語言: C/C++
  • 標簽:

資源簡介

鏈表的基本操作.c

資源截圖

代碼片段和文件信息

#define??_CRT_SECURE_NO_WARNINGS?
#include?
#include?
#include?

typedef?struct?Node
{
int?data;
struct?Node?*next;
}SLIST;

SLIST?*SList_Create();?//創建鏈表
int?SList_Print(SLIST?*pHead);?//遍歷鏈表
int?SList_NodeInsert(SLIST?*pHead?int?x?int?y);?//插入值??在x值之前?刪除y
int?SList_NodeDel(SLIST?*pHead?int?y);
int?SList_Destory(SLIST?*pHead);


SLIST?*SList_Create()
{

SLIST?*pHead?*pM?*pCur;
int data;
//創建頭節點?并初始化
pHead?=?(SLIST?*)malloc(sizeof(SLIST));
if?(pHead?==?NULL)
{
return?NULL;
}
pHead->data?=?0;
pHead->next?=?NULL;

printf(“\nplease?enter?you?data:?“);
scanf(“%d“?&data);

pCur?=?pHead;

while?(data?!=?-1)
{
//創建業務節點?并初始化?不斷接受輸入?malloc新結點
pM?=?(SLIST?*)malloc(sizeof(SLIST));
if?(pM?==?NULL)
{
return?NULL;
}
pM->data?=?data;
pM->next?=?NULL;

//2?新結點?入鏈表?
pCur->next?=?pM;

//3?新結點變成當前節點
pCur?=?pM;??//鏈表結點的尾部追加?

printf(“\nplease?enter?you?data:?“);
scanf(“%d“?&data);
}

return?pHead;
}
int?SList_Print(SLIST?*pHead)
{
SLIST?*tmp?=?NULL;
if?(pHead?==?NULL)
{
return?-1;
}
tmp?=?pHead->next;

printf(“\nBegin\t“);
while?(tmp)
{
printf(“%d?“?tmp->data);
tmp?=?tmp->next;
}
printf(“\tEnd“);
return?0;
}

int?SList_NodeInsert(SLIST?*pHead?int?x?int?y)
{
SLIST?*pM?*pCur?*pPre;

//創建新的業務節點pM
pM?=?(SLIST?*)malloc(sizeof(SLIST));
if?(pM?==?NULL)
{
return?-1;
}
pM->next?=?NULL;
pM->data?=?y;

//遍歷鏈表
pPre?=?pHead;
pCur?=?pHead->next;

while?(pCur)
{
if?(pCur->data?==?x)
{
break;
}
pPre?=?pCur;
pCur?=?pCur->ne

評論

共有 條評論