Linked List

Can anyone clerify this question as i dont understand what it is asking.

Write an algorithm for printing a singly linked list in reverse, using only constant extra space. This instruction implies that you cannot use recursion but you may assume that your algorithm is a list member function. Can such an algorithm be written if the routine is a constant member function

any help would be welcome
Do you know what a linked list is?

If you have a structure (class in OOP terms) similar to this:


1
2
3
4
5
6
7
class Node {
private:
   int data;
   Node *next;
public:
   // some accessing methods.
};


Means you have a list in a flowing form. Singly linked mean that you only have a *next pointer, but not a *prev pointer (or similar connections). Maybe this helps:

(Node 1) -> (Node 2) -> (Node 3)

But only in one direction.
Now its your turn to define a method, thats not recursive and prints the contents in following direction:

(Node-3-data) (Noce-2-data) (Node-1-data)

Could i help you? Do you need help with defining the function? Do you understand what a constant member is? Look into some tutorials in the web. Linked list is a well known and often used tutorial topic.


Maikel
Last edited on
Topic archived. No new replies allowed.