Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. // A facc'ro cazz//
  5.  
  6. typedef struct ll_node_struct{
  7.   int info;
  8.   struct ll_node_struct* next;
  9. } ll_node;
  10.  
  11.  
  12. ll_node* push(ll_node* head, int v){
  13.    ll_node* new = malloc(sizeof(ll_node));
  14.    new->info=v;
  15.    new->next=head;
  16. return new;
  17. }
  18.  
  19. void reverseList(ll_node* l,ll_node* *new){
  20.   if(l==NULL)return;
  21.    *new=push(*new,l->info);
  22.    reverseList(l->next,new);
  23. }
  24.  
  25. void print(ll_node* head){
  26.   ll_node* curr=head;
  27.   while(curr!=NULL){
  28.   printf("%d\n",curr->info);
  29.   curr=curr->next;
  30.  
  31.   }
  32. }
  33.  
  34.  
  35.  int main(){
  36.   int n;
  37.   ll_node* l=NULL;
  38.   ll_node* new=NULL;
  39.  
  40.    do{
  41.      scanf("%d",&n);
  42.         l=push(l,n);
  43.  
  44.      }while(n>0);
  45.  
  46.    printf("\n\n");
  47.    print(l);
  48.    reverseList(l,&new);
  49.    printf("\n\n");
  50.    print(new);
  51.  
  52.   return 0;
  53.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement