Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7616405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:52:43+00:00 2026-05-31T02:52:43+00:00

Possible Duplicate: Reverse a singly linked list reverse a linked list? I have been

  • 0

Possible Duplicate:
Reverse a singly linked list
reverse a linked list?

I have been trying to figure out how to displays the contents of a linked list of numbers in reverse order. I tried changing nodes around and i cant figure it out. its a singly linked list. I thought of implementing a stack. is there a simpler way? heres my code. i need the function to be in the header file, and it will be implemented in the main.cpp. ive been trying for hours today and yesterday and this is really a last resort. i have pages of notes of failed algorithms. as well as pages of google searches but nothing seems to work. if it makes a difference im using Microsoft Visual Studio 2010 (not my first choice). the code i presented does not have what ive been trying as it all failed horribly and usually produced errors.

#ifndef _LINKEDLIST_H
#define _LINKEDLIST_H
#include <iostream>
#include <string>
#include <stack>

#include "Node.h"

using namespace std;
using namespace bruno;

namespace bruno
{
template< typename T>
class LinkedList
{
    private:        Node<T>  * head;
                    Node<T>  * tail;
                    int numberOfNodes;

    public:         LinkedList();
                    ~LinkedList();

                    int length(); 

                    Node<T>  * getHead() { return head; };
                    Node<T>  * getTail() { return tail; };

                    void insertInFront(T d);
                    void insertInBack(T d);

                    static void listContents( Node<T> * head);  

                    static T  sum( Node<T>  * head);    //     assume head is not NULL at call

                    static void  increment( Node<T>  * head, T val); 
                    static void reverseListContents( Node<T> * head, Node<T> * tail, int n );
};


   template< typename T >
   LinkedList<T>::LinkedList()
   {
       head = tail = NULL;
       numberOfNodes = 0;
   }


   template< typename T >
   LinkedList<T>::~LinkedList()
   {
   }



   template< typename T >
   int LinkedList<T>::length()
   { 
       return numberOfNodes; 
   }



   template< typename T >
   void LinkedList<T>::insertInFront(T d)
   {
        Node<T> * p =  new Node<T>;
        p->data  =  d;
        p->next  = head;
        head = p;
        if ( tail == NULL )
            tail = p;
        numberOfNodes++;
   }




   template< typename T >
   void LinkedList<T>::insertInBack(T d)
   {
        if ( tail == NULL )
            insertInFront(d);
        else {
                tail->next = new Node<T>;
                tail = tail->next;
                tail -> data = d;
                tail -> next = NULL;
        }
        numberOfNodes++;

   }


   template< typename T >                       
   void LinkedList<T>::listContents(Node<T> * head)
   {
        if (head == NULL)  return;
        else
        {      cout <<  head->data  << "  ->  ";
               listContents( head -> next );
        }
   }




   template< typename T >                       
   T LinkedList<T>::sum(Node<T> * head)
   {
        if ( (head->next) == NULL )  return  head->data;
        else
             return  ( head->data    +   sum( head->next ) );
   }




   template< typename T >                       
   void LinkedList<T>::increment(Node<T> * head, T  val)
   {
        if ( head == NULL )  return;
        else
        {
            head->data += val;                    // add val to current data value
            increment( head->next, val );
        }

   }

   template< typename T >
   void LinkedList<T>::reverseListContents (Node<T> * head, Node<T> * tail, int n)
   {
       //clueless!


   }



}

#endif 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:52:44+00:00Added an answer on May 31, 2026 at 2:52 am

    You can do it this way:

    1) Find the last node and print it.

    2) Traverse the linked list to find the node that has the node you last printed as its next node, and print it.

    3) Go to step 2 until there are no more nodes to print.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Iterating through a LinkedHashMap in reverse order How to traverse Linked Hash
Possible Duplicate: Can one do a for each loop in java in reverse order?
Possible Duplicate: Default sort-ordering in MySQL (ALTER TABLE … ORDER BY …;) I have
Possible Duplicate: How to display an array in reverse order in objective C I
Possible Duplicate: Loop through associative array in reverse I have a key-value pair javascript
Possible Duplicate: Protect .NET code from reverse engineering? we just develop a application with
Possible Duplicate: What Ruby IDE do you prefer? I've generally been doing stuff on
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: reverse a string in Python I tried searching the python documentation for
Possible Duplicate: Is it possible to decrypt md5 hashes? i have md5 checksum in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.