Question: Problems: Reverse a singly linked list Remove duplicated in a sorted linked list Submission First, look at the following checklist: Have you tested every method?

Problems:
Reverse a singly linked list
Remove duplicated in a sorted linked list
Submission First, look at the following checklist:
Have you tested every method?
Is the indentation easily readable? You can have Eclipse correct indentation by highlighting all
code and select "Source > Correct Indentation".
Are comments well organized and concise?
Grading Criteria
Sort an array (20p)
Find the kth largest element in an array, not sorted (15p)
Reverse a singly linked list (20p)
Remove duplicated in a sorted linked list (20p)
Complete the 4 unimplemented test cases (3 in ArrayProblemsTest.java and 1 in LinkedListProb-
lemsTest.java)(20p)
Source code is appropriately commented (5p)
public class LinkedListProblems {
/*
Given a sorted linked list, delete all duplicates such that each element appear only once.
Example 1:
Input: 1->1->2
Output: 1->2
Example 2:
Input: 1->1->2->3->3
Output: 1->2->3
*/
public static ListNode deleteDuplicates(ListNode head){
//TODO: finish this method.
//TODO: Modify this line to return correct data.
return null;
}
/*
* Reverse a singly linked list.
Example:
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
*/
public static ListNode reverseList(ListNode head){
//TODO:finish this method.
//TODO: Modify this line to return correct data.
return null;
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
public class LinkedListProblemsTest {
ListNode T;
/* The common test data to be used is the list T: 1->1->2->3->3
*/
@Before
public void setUp() throws Exception {
int[] testdata={1,1,2,3,3};
ListNode T = new ListNode(testdata[1]);
for (int i=1; i1->2->3->3->null
Output: 1->2->3->null
*/
@Test
public void testDeleteDuplicates(){
int[] expected ={1,2,3};
ListNode newT=LinkedListProblems.deleteDuplicates(T);
ListNode p=newT;
int i =0;
while (p!=null){
assertEquals(expected[i], p.val);
i = i+1;
}
}
/*
* Reverse a singly linked list.
Example:
Input: 1->1->2->3->3->NULL
Output: 3->3->1->1->1->NULL
*/
@Test
public void testReverseList(){
fail("Not yet implemented"); // TODO
}
}
public class ListNode {
int val;
ListNode next;
ListNode(int x){ val = x; }
}
Please Complete them

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!