KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I wonder if there exists some logic to reverse a singly-linked list using only two pointers. The following is used to reverse the single linked list using three pointers namely p , q , r : struct node { int data; struct node *link; }; void reverse() { struct node *p = first, *q = NULL, *r; while (p != NULL) { r = q; q = p; p = p->link; q->link = r; } first = q; } Is there any other alternate to reverse the linked list? What would be the best logic to reverse a singly linked list, in terms of time complexity?
Tags (comma-separated)
Save Edits
Cancel