初学者。如果有误请指正,欢迎联系QQ2684162190
#include <stdio.h>
#include <string.h>
#include<malloc.h>
typedef struct link
{
int date;
struct link* next;
}Link;
Link* put()
{
Link *node;
node=(Link*)malloc(sizeof(Link));
node->date = -1000;
node->next = NULL;
return node;
}
void insert(Link *head,int newnum)
{
Link * p=head;
Link* node=put();
node->date=newnum;
while(p->next!=NULL)
{
p=p->next;
}
node->next =NULL;
}
void deletelink(Link* head,int newnum)
{
Link *p,*q;
p=head;
q=head;
if(p->next == NULL)
{
printf("链表为空");
return ;
}
else
{
while(p->next!=NULL)
{
p=p->next;
if(newnum==p->date)
{
q->next=p->next;
break; ;
}
q=p;
}
}
}
void ptr_printf(Link *head)
{
Link *p=head;
if(p->next==NULL)
{
printf("链表为空");
return;
}
while(p->next!=NULL)
{
p=p->next;
printf("%d ",p->date);
}
}
void destory(Link *head)
{
Link *p=head;
link *q=head;
while(p->next!=NULL)
{
p=p->next;
free(q);
q=p;
}
free(q);
printf("链表已经释放");
}
int main()
{
return 0;
}