bhupixb

Linked list

Oct 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "stdlib.h"
  3. typedef struct s{
  4. int data;
  5. struct s *prev, *next;
  6. }node;
  7. node* new1(){
  8. node* temp =(node *)malloc(sizeof(node));
  9. return temp;
  10. }
  11. int main(int argc, char const *argv[]){
  12. int n;
  13. node *head, *temp, *start;
  14.  
  15. head = new1() ;
  16. head -> next = NULL;
  17.  
  18. // Remember the head------______-------
  19. start = head;
  20.  
  21. scanf("%d", &n);
  22.  
  23. scanf("%d", &(head->data));
  24.  
  25. while(--n){
  26. temp = new1();
  27. scanf("%d", &(temp->data));
  28. temp->next = NULL;
  29. head->next = temp;
  30. head = head->next;
  31. }
  32.  
  33. while(start != NULL){
  34. printf("%d ", start->data);
  35. start = start->next;
  36. }
  37. return 0;
  38. }
Add Comment
Please, Sign In to add comment