pointers - Method to Reverse a Linked list in c++ -
pointers - Method to Reverse a Linked list in c++ -
i writing method reverse linked list in c++. i'm trying utilize node*
instead of void
homecoming type facing number of errors.
my method code..
node* reverse(node *head) { struct node* prev = null; struct node* current = head; struct node* next; while (current != null) { next = current->next; current->next = prev; prev = current; current = next; } head = prev; }
the compile time error message receiving..
solution.cc: in function 'node* reverse(node*)': solution.cc:24:22: error: cannot convert 'node*' 'reverse(node*)::node*' in initialization node* current = head; ^ solution.cc:28:24: error: invalid utilize of incomplete type 'struct reverse(node*)::node' next = current->next; ^ solution.cc:23:14: error: forwards declaration of 'struct reverse(node*)::node' struct node* prev = null; ^ solution.cc:29:16: error: invalid utilize of incomplete type 'struct reverse(node*)::node' current->next = prev; ^ solution.cc:23:14: error: forwards declaration of 'struct reverse(node*)::node' struct node* prev = null; ^ solution.cc:33:10: error: cannot convert 'reverse(node*)::node*' 'node*' in assignment head = prev; ^ solution.cc:34:1: error: no homecoming statement in function returning non-void [-werror=return-type] } ^ cc1plus: warnings beingness treated errors
node
not same node
, missing return
statement
node* reverse(node *head) { struct node* prev = null; struct node* current = head; struct node* next; while (current != null) { next = current->next; current->next = prev; prev = current; current = next; } head = prev; homecoming head; }
c++ pointers return-type singly-linked-list
Comments
Post a Comment