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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:51:52+00:00 2026-06-11T18:51:52+00:00

Im currently having trouble trying to understand linked lists. I have some code that

  • 0

Im currently having trouble trying to understand linked lists. I have some code that uses nodes and have been asked to use an iterative approach to create a new node with the string parameter stored in it, at the index position specified in the integer parameter. The old node at the index position should follow the newly inserted node.

These are the fields:

  // a string that contains the full name on the filesystem of an image file.
private String imageName;

// a reference to the next ImageNode in the linked list.
private ImageNode next;

//temporary node created to start the set of nodes
private ImageNode temp = this;

And this is the code i have written so far: Note that getNext() returns the next node.

private void addIter(String imageFileStr, int pos) {

    int count = 0;
    while(temp.getNext() != null){
        temp = temp.getNext();
        count++;

        if(count == pos){
          temp.getNext() = ???
        }

    }
}

Is this the right way to go about adding two nodes? If so, this would currently only work if the node needs to be added to the end of the set of current nodes. How would i modify the code so that it allows me to add a node in the middle of set and have the old nodes follow it as stated above (“The old node at the index position should now follow the newly inserted node.”)?

And finally, how do i create a variable (x) that is equal to the input from addIter so that i can set temp.getNext() = x? (currently depicted by question marks in the code).

  • 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-11T18:51:54+00:00Added an answer on June 11, 2026 at 6:51 pm

    It’s impossible to completely answer this without seeing more of your implementation, but here are few things:

    1. temp.getNext() = ??? doesn’t make sense, you can’t assign to a function call. You will need to add a method setNext(ImageNode node) that sets the next node to the given value.

    2. In your add method, You need to create a new node using the input string (lets call it newNode, find the node currently at pos (lets call it existingNode), then you will need to do a couple things:

      • Set newNode.next to the node currently after existingNode (or null if it’s the end of the list)
      • Set existingNode.next to newNode.

    This will probably end up looking something like this:

    public void add(String item, int pos) {
        if (pos > length) {
             // Probably just throw an out of bounds exception
        }
    
        Node existingNode = head;
        for (int i = 0; i < pos; i++)
             existingNode = existingNode.getNext();
    
        Node newNode = new Node(item);
        newNode.setNext(existingNode.getNext());
        existingNode.setNext(newNode);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently having trouble with a live wallpaper that does some very intensive
I'm having some trouble trying to understand how to create a dynamic choice field
I been having trouble trying to figure this out. When I think I have
I am currently having unnecessary trouble trying to test out RubyMine. My biggest problem
I'm having trouble editing an XML file. I'm currently trying to use Nokogiri ,
I'm currently having trouble getting example code for using tweepy to access Twitter's Streaming
The part of the application that I am currently having trouble getting to work
I'm currently having some trouble with getting certain input fields passed along when a
Hey, I currently am having trouble trying to get this to work. Here's a
I am currently having trouble getting a value from an AsyncTask that gets data

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.