Difference between revisions of "TADM2E 3.2"

From Algorithm Wiki
Jump to: navigation, search
(Recovering wiki)
 
(Recovering wiki)
Line 1: Line 1:
<pre>
+
<pre>
 
typedef struct Node {
 
typedef struct Node {
 
     char *value;
 
     char *value;
Line 17: Line 17:
  
 
     while (curr) {
 
     while (curr) {
         next =  curr-&gt;next;
+
         next =  curr->next;
         curr-&gt;next = prev;
+
         curr->next = prev;
 
         prev = curr;
 
         prev = curr;
 
         curr = next;
 
         curr = next;
Line 27: Line 27:
 
     return 1;
 
     return 1;
 
}
 
}
&lt;/pre&gt;
+
</pre>
  
  
 
[[Data-structures-TADM2E|Back to ''Data Structures'' Problems]]...
 
[[Data-structures-TADM2E|Back to ''Data Structures'' Problems]]...

Revision as of 18:22, 11 September 2014

typedef struct Node {
    char *value;
    struct Node *next;
} Node;

int reverse(Node **head) {
    Node *curr, *prev, *next;

    if (!head || !(*head)) {
        return 0;
    }

    curr = *head;
    prev = NULL;
    next = NULL;

    while (curr) {
        next =  curr->next;
        curr->next = prev;
        prev = curr;
        curr = next;
    }

    *head = prev;

    return 1;
}


Back to Data Structures Problems...