Question

given a pointer to the first node of a linked list, you are asked to reverse...

given a pointer to the first node of a linked list, you are asked to reverse the list. Explain, in English, not code, how you would complete such a task if you had a limited amount of memory (not enough to store the whole list twice!)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

  1. Initialize three pointers prev as NULL, curr as head and next as NULL.
  2. Iterate trough the linked list. In loop, do following.
    // Before changing next of current,
    // store next node
    next = curr->next

    // Now change next of current
    // This is where actual reversing happens
    curr->next = prev

    // Move prev and curr one step forward
    prev = curr
    curr = next

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
given a pointer to the first node of a linked list, you are asked to reverse...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Given a pointer to the root of a binary search tree (has left, right,...

    In C++ Given a pointer to the root of a binary search tree (has left, right, and parent pointers as well as a data section ) write a function (or functions) which will return an STL list (you should not define this class, it’s already included) with all of the values from the tree in sorted order. Your code should run in theta(N) time. for the second part,.given a pointer to the first node of a linked list, you are...

  • You are given a pointer head to the first node in a linked list. Each node...

    You are given a pointer head to the first node in a linked list. Each node points to the next node. We call the list a snail if the last node points to some node v in the list. We call the list a snake if the last node points to NULL. The list has n nodes. You are not allowed to change the list (permanently or temperately). You are allowed to use O(1) extra memory. The value of n...

  • Given the node structure and the head pointer (headptr) of a linked list write a code...

    Given the node structure and the head pointer (headptr) of a linked list write a code to move the last element to the head of the list. struct node {    int value;    struct node *next; };

  • Problem Statement This problem provides you with a linked list composed of node objects chained together...

    Problem Statement This problem provides you with a linked list composed of node objects chained together via node pointers. Each node has a next pointer which points to the next node in the chain. The last node is identified by having a NULL (or nullptr) next pointer. The linked lists for this problem store string data. Your task: identify the longest string stored in the linked list. If two strings are of the same length, return the string that occurred...

  • 1. A linked list does not need to have a pointer that points to the first...

    1. A linked list does not need to have a pointer that points to the first node of the list. True or False? 2. A linked list needs to have a pointer to point to the last node of the list.  True or False? 3. If "head" is the only pointer that points to the first node of a linked list, to traverse the list, you should move the head pointer to each node one at a time.  True or False? Please...

  • Write a function named reverse Display that takes a pointer to the first node of a...

    Write a function named reverse Display that takes a pointer to the first node of a linked list and displays the data in each node in the list from last to first. Assume the following node structure: struct node Type int dota; node Type "next; // points to next node in List }; BIV AA- IEE 3. x' x, EE V + TT TT 12pt Paragraph FR

  • Answer all questions 1- in circular singly linked list, previous pointer of the first node points...

    Answer all questions 1- in circular singly linked list, previous pointer of the first node points to which node A. First node B. Itself C. null D. Last node 2- Which of the following is NOT an applications of linked lists? A. Implementation of stacks and queues B. Dynamic memory allocation C. Manipulation of polynomials D. Keeping people at home during epidemics like corona virus 3- In a circular singly linked list? A. Components are all linked together in some...

  • Exercise: Delete First Element from a Linked List (pair) This is a pair exercise to complete...

    Exercise: Delete First Element from a Linked List (pair) This is a pair exercise to complete with your lab partner. Download list_delete_first.c here, or copy it to your CSE account using the following command: cp -n /web/dp1091/20T1/activities/list_delete_first/list_delete_first.c . Your task is to add code to this function in list_delete_first.c: // // Delete the first node in list. // The deleted node is freed. // The head of the list is returned. // struct node *delete_first(struct node *head) { // PUT...

  • Arrays, Lists, Stacks and Queues: 1) Write C++ code to reverse a singly-linked list L using...

    Arrays, Lists, Stacks and Queues: 1) Write C++ code to reverse a singly-linked list L using only a constant amount of additional storage and no recursion. Assume the list object has a head pointer _head and consists of Node objects; a Node object has a pointer Node* _next

  • Using Java You are given a Node class and a List class: public class Node {...

    Using Java You are given a Node class and a List class: public class Node {    int   data;     Node next; } public class List {     Node first; } You are also given a Stack class. The following functions are available for use: public class Stack { public boolean isEmpty(){}; public void push(int n){}; public int pop(){};} Write a Java method snglyRevToStck that pushes the data found in a linked list t in reverse order into the stack...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT