69,368
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
typedef struct List
{
int data;
struct List *Next;
}Node,*NodePtr;
NodePtr ListPtr;
void ListInsert(NodePtr L,int i)
{
NodePtr p;
NodePtr q;
p = L;
//while(p)
while(p->Next)
{
p = p->Next;
}
q = (Node*)malloc(sizeof(Node));
if (!q)
exit(0);
q->data = i;
printf("111\n");
p->Next = q;
printf("111\n");
p = q;
p->Next = NULL;
}
void ListCreatTail(NodePtr *L)
{
*L = (Node*)malloc(sizeof(Node));
if (!(*L))
exit(0);
(*L)->Next = NULL;
}
void ListDelete(NodePtr L, int i)
{
int j = 1;
NodePtr p,q;
p=L;
//while(p,j < i)
while(p && j < i)
{
p=p->Next;
++j;
}
q=p->Next;
p->Next = q->Next;
free(q);
}
void ListPrintf(NodePtr L)
{
NodePtr p;
p=L->Next;
while(p)
{
printf("%d\n",p->data);
p=p->Next;
}
}
//void main()
int main()
{
ListCreatTail(&ListPtr);
ListInsert(ListPtr,1);
/* ListInsert(ListPtr,2);
ListInsert(ListPtr,3);
ListInsert(ListPtr,4);
ListInsert(ListPtr,5);
ListDelete(ListPtr,2);*/
ListPrintf(ListPtr);
return 0;
}