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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:42:42+00:00 2026-06-13T10:42:42+00:00

I have an add method for creating a linked list that is unordered and

  • 0

I have an add method for creating a linked list that is unordered and has a trailer node defined by

 ListNode<E> front = new ListNode<E>(null,null);

from what I understand I can keep on adding values to the front of the list BUT since this is a Linked List implementation of a Set and I can’t have a duplicate values, I need to check the set (each listnode from front to trailer node) to make sure it does not have the new value I’m trying to add into the list. Here is my add method.

public boolean add(E e) {

  ListNode<E> newNode = new ListNode<E>(e, null);

      //point to trailer      
      newNode.next = front.next;
      //front now points to newNode
      front.next = newNode;
      //front->newNode->trailer

       objectCount++;

        return true;

}

Now, to check the that the newNode is not already in the linked list I need to implement a contains method that checks each element in the list and returns true if it is in the linked list. IF it returns true then I don’t execute the add method above and if I don’t then I successfully add the value. So, I was thinking something along the lines of:

 if(this.contains(newNode))
   return false;
 else {
   newNode.next = front.next;
   front.next = newNode;
  }

But I don’t know how to implement my contains method successfully. Heres what I have:

public boolean contains(Object o) {
   ListNode<E> o1 = (ListNode<E>) o;
  if (o1.value == front.next.value)
          return true;
      else
          return false;
}

I’m not sure how I can make the method contains, check each node for the Object o and return true if it is in the linked list and false otherwise. So, going forward, is my understanding correct on how I should implement this? And how can I fix my contains method?

  • 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-13T10:42:43+00:00Added an answer on June 13, 2026 at 10:42 am

    Every node knows whats before and whats behind it. Thus:

    Go over all previous nodes, until there is noone anymore, check them.

    Go over all following nodes, until there is noone anymore, check them.

    (Because it sounds like an exercise, without code. But you just have to “translate” the written words into code)

    –tb

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

Sidebar

Related Questions

I have trouble doing this. I'm creating a method that add working days on
Let's say I have a simple ASP MVC3 list controller, with an add method,
I have a data object that has many different List properties. I want to
I'm creating a doubly-linked list in Objective-C. I would like my node class to
I have a COM interface and need to add an accessor method to it.
So, I have implemented this method to add a footer to my table view:
i have written a method in java like this public boolean ADD(String ID,String Name,String
I have a fairly standard .Net MVC Controller method: public ActionResult Add(Customer cust) {
Greetings, I have a method to capture packets. After capturing I want to add
I have an add this button on the website that is rendering a border

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.