akevintg

Linked List

Mar 13th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3.  
  4. struct list_el {
  5.    int val;
  6.    struct list_el * next;
  7. };
  8.  
  9. typedef struct list_el item;
  10.  
  11. void main() {
  12.     item * curr, * head;
  13.     item *last;
  14.     int i;
  15.     int input;
  16.     head = NULL;
  17.     int x=1;
  18.     do{
  19.         curr = (item *)malloc(sizeof(item));
  20.         printf("Masukan Angka : ");
  21.         scanf("%d",&input);fflush stdin;
  22.         curr->val = input;
  23.         curr->next  = head;
  24.         head = curr;
  25.         system("cls");
  26.         for(i=1,curr=head;curr!=NULL;i++){
  27.             printf("%d", curr->val);
  28.             curr = curr->next ;
  29.             if(i!=x)
  30.                 printf(" -> ");
  31.         }
  32.         x++;
  33.         printf("\n");
  34.     }while(x!=10);
  35.     getchar();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment