苹果首席架构师
发表于 2017-4-9 12:53:01
链表操作
自拍港
发表于 2017-5-8 22:58:17
看看
ljx719476856li
发表于 2017-5-9 20:15:25
顶
wangjia911
发表于 2017-5-31 12:15:54
学习
shitiezhu
发表于 2017-6-1 10:34:44
123
易范德德
发表于 2017-6-6 15:41:38
是
disshu
发表于 2017-6-8 00:27:41
可见
时间过得很快
发表于 2017-6-11 21:22:19
顶。。
{:5_92:}
那片星海
发表于 2017-6-13 10:41:31
回复了看看,谢谢分享
小X学X森
发表于 2017-6-26 15:48:23
支持支持支持支持支持
小X学X森
发表于 2017-6-26 15:54:41
支持楼主
q401201302
发表于 2017-7-1 08:46:04
我想看看
阳光加冰
发表于 2017-7-2 00:51:06
#include <stdio.h>
#include <stdlib.h>
#define ERROR 0
#define SUCCESSFULLY 1
typedef int ElemType;
typedef int Status;
typedef struct Node
{
ElemType data;
struct Node *next;
} Node, *List;
Status InitList(List *plist)
{
*plist = (Node*)malloc(sizeof(Node));
if(!*plist)
return ERROR;
// 填充头结点的数据域
(*plist) -> data = 0;
(*plist) -> next = NULL;
return SUCCESSFULLY;
}
Status InsertElem(List *plist, int loc, ElemType e)
{
if(loc > (*plist) -> data + 1)
return ERROR;
int i;
Node *pscan = *plist;
for(i = 1; i < loc; i++) // 迭代寻找第loc-1个节点
pscan = pscan -> next;
Node *pnew = (Node*)malloc(sizeof(Node)); // 为新节点分配空间
if(!pnew)
return ERROR;
pnew -> data = e; // 填充数据域
// 连接操作
pnew -> next = pscan -> next;
pscan -> next = pnew;
(*plist) -> data++; // 链表长度计数+1
return SUCCESSFULLY;
}
Status Remove(List *plist, int loc, ElemType *e)
{
if(loc > (*plist) -> data)
return ERROR;
int i;
Node *pscan = *plist;
for(i = 1; i < loc; i++)
pscan = pscan -> next;
pscan -> next = pscan -> next -> next;
(*plist) -> data--; // 计数-1
return SUCCESSFULLY;
}
void ShowList(List *plist)
{
int n = (*plist) -> data, i;
Node *pscan = (*plist) -> next;
for(i = 0; pscan && i < n; i++, pscan = pscan -> next)
printf("%d ", pscan -> data);
printf("\n");
}
void DestroyList(List *plist)
{
Node *pscan = (*plist) -> next,
*ptemp;
while(pscan)
{
ptemp = pscan;
pscan = pscan -> next;
free(ptemp);
}
free(*plist);
}
int main()
{
int input, i = 1;
List mList;
ElemType data;
InitList(&mList);
while(scanf("%d", &input) && input)
InsertElem(&mList, i++, input);
ShowList(&mList);
Remove(&mList, 5, &data);
ShowList(&mList);
DestroyList(&mList);
}
linxinye
发表于 2017-7-5 16:14:28
ferawgr
我叫潜水袁
发表于 2017-7-8 08:40:48
代码清单
zhuchuanshuai22
发表于 2017-7-8 21:17:44
1
莱昂纳多
发表于 2017-7-19 20:13:06
阿斯顿
孙宝宝的小仙女
发表于 2017-7-21 18:39:55
对答案啦
ayang
发表于 2017-7-27 15:24:53
aaaaa
swpen888
发表于 2017-8-9 16:23:47
好好学习,哈