Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node{
  4.     int data;
  5.     struct node *next;
  6. };
  7. struct node *head=NULL;
  8. struct node *current=NULL;;
  9.  
  10. int main(){
  11.     insertItem(10);
  12.     insertItem(100);
  13.     insertItem(1000);
  14.  
  15.     printList(head);
  16. return 0;
  17. }
  18.  
  19.  
  20. void insertItem(int d){
  21.     struct node *newNode=(struct node *)(malloc(sizeof(struct node)));
  22.     newNode->data=d;
  23.     newNode->next=NULL;
  24.  
  25.     if(head==NULL){
  26.         head=newNode;
  27.         current=head;
  28.     }else{
  29.         current->next=newNode;
  30.         current=current->next;
  31.     }
  32.  
  33. }
  34.  
  35. void printList(struct node *temp){
  36.     while(temp!=NULL){
  37.        printf("%d\n", temp->data);
  38.        temp=temp->next;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement