#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int date;
struct node *next;
}List;
void createlist(List*head,int n)
{
int i;
List *p=head,*q;
for(i=0;i<n;i++)
{
q =(List*)malloc(sizeof(List));
q->next = NULL;
scanf(" %d",&q->date);
p->next = q;
p=q;
}
p->next =NULL;
}
void delelist(List*head,int m,int n)
{
int i;
List *p=head;
if(m>n+1||m<2)
{
printf("error!");
exit(0);
}
else
{
for(i=1;i<m-1;i++)
{
p=p->next;
}
p->next=p->next->next;
}
}
void Print(List *head)
{
List *p =head->next;
while(p!=NULL)
{
printf("%d ",p->date);
p=p->next;
}
}
int main()
{
int n,m;
List *head = (List*)malloc(sizeof(List));
head ->next =NULL;
scanf("%d",&n);
createlist(head,n);
scanf("%d",&m);
delelist(head,m,n);
Print(head);
return 0;
}
953: 单链表的删除操作的实现
最新推荐文章于 2024-05-28 14:35:23 发布