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

  • Home
  • SEARCH
  • 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 3962656
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:07:20+00:00 2026-05-20T03:07:20+00:00

public void insertIt (Node firstNode, Node newNode) { firstNode.next = newNode; newNode.next = null;

  • 0
public void insertIt (Node firstNode, Node newNode) {
 firstNode.next = newNode;
 newNode.next = null;   
}

I couldn’t find the class that uses .next, can anyone show me? Also, I don’t really understand this. I’m setting firstNode.next=newNode, so how would firstNode include firstNode.next? I hope that makes sense.

From my notes:

> Example 1 to practice with links: 
> Node node1 = new Node(22); Node node2
> = new Node(44); firstNode = node1; node1.next = node2; node2.next = null;
> Produces:
>     firstNode -> 22 -> 44 -> null So firstNode.data is 22 and
> firstNode.next.data is 44. Since
> firstNode.next.next is null, a
> reference to  firstNode.next.next.data
> is an error.
> 
> Example 2 to practice with links: What
> is node3.data ?
>     node3 -> 99 -> null
>     Answer: 99
> 
> Example 3 to practice with links:
> public void insertIt (Node firstNode,
> Node newNode) {
>      firstNode.next = newNode;
>      newNode.next = null;  }

Edit: What happens if you assign a node to another node?

For example, head -> 2 -> 3 -> null

node1 = node2;

What is changing? Is node1s value 3? or is it changing its reference/pointer?

  • 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-20T03:07:20+00:00Added an answer on May 20, 2026 at 3:07 am

    After seeing your comment, I think I understand what you’re attempting to do. This code is from an implementation of a LinkedList Data Structure. You should read the wikipedia article, but in short, a linked list is made up of Nodes that contain a data element along with a pointer to the next element in the list. Because of this, it is possible to traverse the list in order with knowledge of only the first element. The .next is used to access the next data member relative to the current node. When you insert an element, you usually need to do something like this:

    public void insertNode(Node nodeBefore, Node newNode){
      newNode.next = nodeBefore.next;
      nodeBefore.next = newNode;
    }
    

    This method inserts the Node newNode after the Node nodeBefore so that when you traverse the list, after you reach nodeBefore you reach newNode. Typically, the end of the list of signified by a null pointer.

    Edit To address your comment, the class Node likely looks like this:

    public class Node{
      public Node next;
      public Object data;
    }
    

    That is where next comes from. It’s a public data member of the Node class

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

Sidebar

Related Questions

//node.h class node { public: void sort(node n); }; I didn't try the code
E,g class Test { public: void setVal(const std::string& str) { this.isVal = str; //This
In the following snippet: public class a { public void otherMethod(){} public void doStuff(String
Considering such code: class ToBeTested { public: void doForEach() { for (vector<Contained>::iterator it =
Given a declaration like this: class A { public: void Foo() const; }; What
public delegate void ExecuteCallback(); class Executioner { private ExecuteCallback _doExecute; public void AddMultiple() {
public class XXX { public static void main(String args[]) { JComponent comp = new
public class Main { public static void main(String[] args) { int[] x = {1,
public void test() { List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); for (int
[TestMethod] public void Memory() { var wr = new WeakReference(aaabbb); Assert.IsTrue(wr.IsAlive); GC.Collect(); GC.Collect(); GC.Collect();

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.