单链表的整表删除

#include<stdio.h>
#include<stdlib.h>
typedef struct{
	char name[10];
	int age;
	int adress;
}Student;
typedef struct Node{
    Student data;
	struct Node * Next;
}Node;
int init_Node(Node **h)
{ if((*h=(Node *)malloc(sizeof(Node)))==NULL) return 0;
  (*h)->Next=NULL;
  return 1;
}
void Creat_list(Node *h)
{ Node *p,*r;
  r=h;
  p=NULL;
  Student a[100];
  int n,i;
  printf("请输入单链表节点个数:");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {printf("请输入第%d个节点的值:",i+1);
   scanf("%s%d%d",a[i].name,&a[i].age,&a[i].adress);
  }
  for(i=0;i<n;i++)
  { p=(Node *)malloc(sizeof(Node));
   if(p==NULL)
   {return;}
   p->data=a[i];
   p->Next=NULL;
   r->Next=p;
   r=p;
  }
}
void Delete_list(Node **h)
{ Node *p,*q;
p=(*h)->Next;
while(p)
{q=p->Next;
free(p);
p=q;
}
(*h)->Next=NULL;
}
void print_Node(Node *h)
{ Node *p=h->Next;
  while(p!=NULL)
  { printf("%s%5d%5d\n",p->data.name,p->data.age,p->data.adress);
   p=p->Next;
  }
}
int main()
{Node *head;
int i;
init_Node(&head);
Creat_list(head);
print_Node(head);
Delete_list(&head);
print_Node(head);
return 0;
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值