SHARE
TWEET

Untitled

a guest Feb 21st, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <Foundation/Foundation.h>
  2.  
  3. typedef struct Node{
  4.     int data;
  5.     Node *next;
  6. } Node, *List;
  7.  
  8. Node *revert(Node *head) {
  9.     Node *next = head->next;
  10.     if (next == NULL) {
  11.         return head;
  12.     }
  13.     Node *result = revert(next);
  14.     next->next = head;
  15.     return result;
  16. }
  17.  
  18. int main(int argc, const char * argv[]) {
  19.     @autoreleasepool {
  20.         Node *head = new Node();
  21.         head->data = 0;
  22.         head->next = NULL;
  23.         Node *current = head;
  24.         for (int i = 1; i < 10; i++) {
  25.             Node *node = new Node();
  26.             node->data = i;
  27.             node->next = NULL;
  28.             current->next = node;
  29.             current = node;
  30.         }
  31.        
  32.         Node *revertNode = revert(head);
  33.         head->next = NULL;
  34.         current = revertNode;
  35.         while (current != NULL) {
  36.             printf("%d \n", current->data);
  37.             current = current->next;
  38.         }
  39.     }
  40.     return 0;
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top