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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:24:34+00:00 2026-06-13T14:24:34+00:00

I have a generic ordered Linked List class. For some reason, LinearNode head is

  • 0

I have a generic ordered Linked List class. For some reason, LinearNode head is being reassigned every single time I run add(). Any ideas? Why would head be changed each time I run this? I’m not even touching it. I can provide the other classes for testing, if needed.

 public class myOrLiList<T extends Comparable<T>> {

public LinearNode head;
public int count;

public myOrLiList() {
    head = null;
    count = 0;

}

// LinearNode INNER CLASS
public class LinearNode {
    public LinearNode next;
    public T item;

    public LinearNode(T thisitem) {
        this.next = null;
        this.item = thisitem;
    }

}
public boolean isEmpty() {
    return (head == null);
}
public void add(T thisItem) {

    LinearNode newNode = new LinearNode(thisItem);

    if (isEmpty()) {
        head = newNode;
        System.out.println("head filled!");
    } else {
        LinearNode compareNode = head;
        do {
            if (thisItem.compareTo(compareNode.item) < 0) {
                newNode.next = compareNode;
                break;
            } else if ((thisItem.compareTo(compareNode.item) < 0)
                    || (thisItem.compareTo(compareNode.item) == 0)) {
                newNode.next = compareNode.next;
                compareNode.next = newNode;
                break;
            } else {
                compareNode = compareNode.next;
            }
        } while (compareNode.next != null);
    }
    System.out.println("Added!");
    count++;
}

Thanks for your help.

  • 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-13T14:24:35+00:00Added an answer on June 13, 2026 at 2:24 pm

    While this class has some errors (Thanks for the tips, Michael!) the question I asked did not come from these errors.

    In the new object class I had created for T, I had declared static properties. So, each time a new T thisItem was being created, all of the properties of all objects were being changed.

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

Sidebar

Related Questions

I have a generic linked-list that holds data of type void* I am trying
Assume I have generic list L of some type in c#. Then, using linq,
I have Generic list holding root objects means I have: public class Component {
I have generic list which must be a preserved order so I can retrieve
I have generic type that looks like: public class GenericClass<T, U> where T :
I want to write in Delphi (2009 - so I have generic dictionary class)
I have a Generic List object which hold below table as its own value.
I have a Generic Base Class that I want to allow one of two
I have a generic Print method that iterates over a list and simply prints
I have generic async task class which fetches response from server . And i

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.