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

The Archive Base Latest Questions

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

I have to write a linked list for social security numbers and implement all

  • 0

I have to write a linked list for social security numbers and implement all the operation on my own. I wrote the Node class and the list but i am having trouble implementing the sortedGet(int index) method. What am i doing wrong in that method?

package listpackage;

import listpackage.SocialNode;

public class SortedListRefBasedDuplicates{
private SocialNode head;
private int numItems = 0;


public SortedListRefBasedDuplicates(){
    head = null;
}

public SocialNode getHead(){
    return this.head;
}

public boolean sortedIsEmpty(){
    return numItems == 0;
}

public int sortedSize(){
    return numItems;
}

public SocialNode sortedGet(int index){
    if(index == 0)
        return head;
    //else if(index >= 0 && index < sortedSize()){
        //for (int i = 0; i < index; i++){
            //head = head.getNext();
        //}
        //return head;
    //}else{
        //return null;
    //}
    else
        return null;
}

public void sortedAdd(int social){
    if(this.sortedIsEmpty()){
        head = new SocialNode(social);
        head.setNext(null);
        numItems++;
    }else{
        int socialIndex = locateIndex(social);
        if(socialIndex == this.sortedSize()){
            SocialNode curr = sortedGet(socialIndex-1);
            SocialNode scn = new SocialNode(social);
            curr.setNext(scn);
            numItems++;
        }else{
            if(socialIndex == 0){
                SocialNode scn = new SocialNode(social);
                scn.setNext(head);
                head = scn;
                numItems++;
            }else{
                SocialNode curr = sortedGet(socialIndex-1);
                SocialNode prev = sortedGet(socialIndex-2);
                SocialNode scn = new SocialNode(social, curr);
                prev.setNext(scn);
                numItems++;
            }
        }
    }
}

public void sortedDelete(int social){

}

public int locateIndex(int social){
    if(numItems == 0)
        return 0;
    else{
        int index = 0;
        while(head != null){
            if(head.getData() < social){
                index ++;
                head = head.getNext();
            }
            else{
                break;
            }
        }
        return index;
    }
  }
}

package listpackage;

public class SocialNode{
private int social;
private SocialNode next;

public SocialNode(int social){
    this.social = social;
    next=null;
}

public SocialNode(int social, SocialNode nextNode){
    this.social = social;
    this.next = nextNode;
}

public int getData(){
    return social;
}

public SocialNode getNext(){
    return next;
}

public void setSocial(int s){
    social = s;
}

public void setNext(SocialNode s){
    next = s;
}
}

Added sortedDelete Method

public void sortedDelete(int social){
if(sortedIsEmpty()){
    System.out.println("List is Empty");
}
else if(sortedSize() == 1){
    if(head.getData() == social)
        head = null;
}else{
    SocialNode x = head;
    if(x.getData() == social)
        head = head.getNext();
    else{
        int count = 1;
        while(x!= null){
            if(x.getData() == social && x.getNext() != null){
                sortedGet(count-1).setNext(sortedGet(count+1));
                break;
            }else{
                sortedGet(count-1).setNext(null);
            }
            x = x.getNext();
            count ++;
        }
    }
  }
}

How do i remove a node from the list given the value of the node?

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

    The main problem I see is that you are iterating on the list by directly modifying the head instance variable, so the list gets modified while you iterate on it, you should use a local variable instead.

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

Sidebar

Related Questions

I have an assignment that requires us to implement a doubly linked list class.
I am implementing my own linked list in Java. The node class merely has
i'm trying to write dynamically linked list of complex numbers. Basically: I have a
For my programming class I have to write a linked list class. One of
I have a class called LinkStrand which functions very similarly to a Linked List.
I'm trying to write a basic, singly-linked list class in C++. I did it
I have a linked list of Nodes, each Node is defined as: struct Node
I want to write a linked list that can have the data field store
I'm creating a doubly-linked list in Objective-C. I would like my node class to
I wrote a linked list implementation for my java class earlier this year. This

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.