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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:18:08+00:00 2026-06-11T19:18:08+00:00

I am lost and really hope someone could help me out here, I am

  • 0

I am lost and really hope someone could help me out here, I am supposed to create a function that finds duplicated number nodes and delete the duplicates. Whenever I run the whole code I am stuck in an infinite loop inside while(current.next != null).

My main question is, I know my problem resides in if (tester.data == current.data). I do not understand why they never test or compare (their ints). I am sorry if this is a vague question I have been staring at my screen baffled for hours.

public void removeDuplicate()
{
    // removes all duplicate nodes from the list

    Node tester = head;
    Node previous = head;
    Node current = head.next;

    while (tester.next != null){
        int i = 0;
        while(current.next != null){
            System.out.println("Stuck here3");
            if (tester.data == current.data){
            Node tempNode = current.next;
                previous.next = tempNode;
                current = tempNode;
                size--;
                System.out.println("Stuck here2");
                break;
                }

            else{   
                previous = current;
                current = current.next;
            }

        }
        System.out.println("Stuck here1");
        tester = tester.next;
        current = tester.next;
    }

}
  • 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-11T19:18:09+00:00Added an answer on June 11, 2026 at 7:18 pm

    My main question is, I know my problem resides in if (tester.data == current.data). I do not understand why they never test or compare (their ints). I am sorry if this is a vague question I have been staring at my screen baffled for hours.

    No, that’s not your problem. They do in fact test and compare, and the deletion of the node works when that happens.

    There are, however, other problems in your code.

    Because of the break in the inner loop, you only remove one duplicate for each value.

    If you remove that break it gets closer, but at the end of the loop, you have

        tester = tester.next;
        current = tester.next;
    

    and you don’t set previous to an appropriate new value.

    It should be

        tester = tester.next;
        previous = tester;
        current = tester.next;
    

    With both these changes made, your code deletes all duplicates except if one occurs at the very end of the list.

    I suspect I could fix that as well, but I’m more inclined to do pretty much a complete rewrite. If I do, I may post it.

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

Sidebar

Related Questions

I hope that someone could help me with the following problem because I'm really
I've got a massive problem and I really hope you can help me here...
HELP......Just moved to C# from vb and Im really lost with this. var ldapmembershipUser
I really hope you can help me as I am about to just throw
Im getting really lost on how to use HttpContext.User. I read everywhere that its
Guys, I opened this question (I hope could help some others) but reading stackoverflow
I'm really lost here. I already checked many answers to how to add something
I am really lost here, i am trying to find my way around xml
This is probably really easy, but I'm lost on how to make sure it
I find my self lost while trying to create an actually pretty easy SQL

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.