Implementation of a List in Java
<p>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?</p>

<pre><code>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 &gt;= 0 &amp;&amp; index &lt; sortedSize()){
        //for (int i = 0; i &lt; 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() &lt; 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;
}
}
</code></pre>

<p>Added sortedDelete Method</p>

<pre><code>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 &amp;&amp; x.getNext() != null){
                sortedGet(count-1).setNext(sortedGet(count+1));
                break;
            }else{
                sortedGet(count-1).setNext(null);
            }
            x = x.getNext();
            count ++;
        }
    }
  }
}
</code></pre>

<p>How do i remove a node from the list given the value of the node?</p>
