All pastes #46742 Raw Edit

awan

public text v1 · immutable
#46742 ·published 2006-03-23 21:43 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>

struct linked_list {
    int data;
    struct linked_list * next;
};

typedef struct linked_list item;

int add(item **p, int d)
{
  item *ptr; 
  ptr = (item *) malloc(sizeof(item));
  ptr->data = d;
  ptr->next = *p;
  *p =ptr;
}

void view(item *p)
{
   if (p) {
     printf("%d\n", p->data);
     view(p->next);
   }
   
}
int main(int argc, char *argv[])
{
  int k=5; item *pp=NULL;
  int i;
  for (i=1; i<=10; i++)
     add(&pp,i); 
  view(pp);
  return EXIT_SUCCESS;
}