/*
* =====================================================================================
*
* Filename: link2.c
*
* Description:
*
* Version: 1.0
* Created: 06/08/2012 10:58:27 PM
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <stdlib.h>
typedef struct node* listp;
typedef struct node{
int data;
listp next;
} node;
void display_list(headl)
{
listp iter;
iter=headl;
while(iter->next!=NULL)
{
printf("%5d",iter->next->data);
iter=iter->next;
}
}
listp init_list()
{
listp headl;
headl=(listp)malloc(sizeof *headl);
headl->next=NULL;
headl->data=-1;
return headl;
}
listp create_list(listp headl,int len)
{
listp iter=headl;
int i=0;
for(i=len;i>0;i--)
{
iter->next=(listp)malloc(sizeof *iter);
iter=iter->next;
scanf("%d",&(iter->data));
}
return headl;
}
main()
{
listp headl;
headl=init_list();
int n=0;
printf("please enter num n:");
scanf("%d",&n);
create_list(headl,n);
display_list(headl);
}