逆置单链表

来源:互联网 发布:mac 邮件 绑定qq邮箱 编辑:程序博客网 时间:2024/04/30 11:31

#include<stdio.h>
#include<malloc.h>
typedef struct node
{
 int data;
 struct node *next;
}node;
node *creat_linklist()
{
 node *head, *p;
 head=(node *)malloc(sizeof(node));
 head->next=NULL;
printf("creat a linklist--Last to Fist Out /n ");

 do
 {
  p=(node *)malloc(sizeof(node));
  scanf("%d", &(p->data));
  p->next=head->next;
  head->next=p;
 }while(getchar()!='/n');
 return head;
}
void search_print(node *head)
{
 node *p=head->next;
 while(p)
 {printf("%d", p->data);
 p=p->next;
 }
}
void main()
{
 node *head;
 head=creat_linklist();
 search_print(head);

原创粉丝点击