bhupixb

Linked list reverse print

Oct 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 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. scanf("%d", &n);
  19.  
  20. scanf("%d", &(head->data));
  21.  
  22. while(--n){
  23. temp = new1();
  24. scanf("%d", &(temp->data));
  25. temp->next = head;
  26. head = temp;
  27. }
  28. start = head;
  29. while(start != NULL){
  30. printf("%d ", start->data);
  31. start = start->next;
  32. }
  33. return 0;
  34. }
Add Comment
Please, Sign In to add comment