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 8734527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:51:27+00:00 2026-06-13T09:51:27+00:00

I have a class called LinkStrand which functions very similarly to a Linked List.

  • 0

I have a class called LinkStrand which functions very similarly to a Linked List. It has toString(), size(), append(), next(), and value(), but NOT a previous() method. I am trying to write code that reverses the order of the nodes, as well as the string within each node. In order to make it easier on myself in a few of the other methods I’ve had to write, I got rid of the next node requirement in constructing a node. Here’s what the Node class looks like:

private class Node {
    public Node myNext;
    public String myData;

    Node(String value) {
        myData = value;
        //myNext = next;
    }   
}

My .reverse() method currently reverses all of the strings within the nodes individually, but does not reverse the order of the nodes themselves. It is copied below:

public IDnaStrand reverse() {
    if (this == null)
        return this;
    Node prevStrand = null;
    Node thisStrand = myHead;
    String revString;
    LinkStrand val = new LinkStrand();
    while (thisStrand != null){
        Node hold = thisStrand.myNext;
        if (revSave.containsKey(thisStrand.myData)){
            revString = revSave.get(thisStrand.myData);
            val.append(revString);
            //System.out.println("Val is: " + val);
        }
        else{
            revString = reverseStr(thisStrand.myData);
            val.append(revString);
            //System.out.println("Val is: " + val);
            revSave.put(thisStrand.myData, revString);
        }
        thisStrand.myData = revString;
        thisStrand.myNext = prevStrand;
        prevStrand = thisStrand;
        thisStrand = hold;
    }
    return val;
}

I’ve been trying to come up with some kind of way to reverse the node order, but I’m drawing a blank. Does anyone have any idea how I might go about it?

Thanks!

  • 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-06-13T09:51:30+00:00Added an answer on June 13, 2026 at 9:51 am

    If you are allowed to modify IDnaStrand and LinkStrand, add a method prepend(Node n). Then, as you iterate through the list, just prepend each node.

    If you can’t modify your classes, save the Nodes to an array in reverse order (nodeArray[size-1], nodeArray[size-2], …) then create a new LinkStrand going through the array in order. Alternatively you could load the array in order, then create the LinkStrand in reverse order.

    example:

    thisStrand = myHead;
    int size = 0;
    while(thisStrand != null){
        thisStrand = thisStrand.myNext;
        size++;
    }
    Node[] nodeArray = new Node[size];
    thisStrand = myHead;
    for(int i = size-1, i < 0; i--) {
        nodeArray[i] = thisStrand;
    }
    

    Now you have the array, just load it into a new list! Of course adding a prepend method would be better, just have the class do

    newElement.myNext = MyHead;
    MyHead = newElement;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Flamethrower which naturally has its own ammunition that is
I have a class called Property which has nothing but get -methods. All the
I have a class called user which has a lname field. Is this the
I have a class called GestorePersonale which holds a list of instances of another
I have a class called class Car , which has be instantiated as the
I have class called ItemList, which is used to provide a list of suggested
Java Code In Java code I have class called IdentificationResult which has 3 members:
I have a class called Trial which has_many results. Now What I want to
I have a class called Metadata, which is declared within the namespace A::B::C ,
I have a class called Path for which there are defined about 10 methods,

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.