SlideShare a Scribd company logo
here is the starter code:
public class LinkedListPracticeLab {
private LinkedListPracticeLab(){}
public static void main(String[] args) {
// Test all methods here
}
/**
* Given the heads of two sorted linked lists, merges the two lists in a one
sorted list.
* The list is made by splicing together the nodes of the original two lists,
without
* creating any new nodes.
*
* Returns the head of the merged linked list.
*/
public static ListNode mergeLists(ListNode head1, ListNode head2) {
return null;
}
/**
* Given the head of a sorted linked list, deletes all duplicates such that
each element appears only once.
*
* Returns the head of the resulting linked list, which is still sorted.
*/
public static ListNode deleteDuplicates(ListNode head) {
return null;
}
/**
* Given the head of a linked list and an integer val, removes all the nodes of
the linked list that has
* Node.val == val.
*
* Returns the head of the resulting list.
*/
public static ListNode removeElements(ListNode head, int val) {
return null;
}
/**
* Given the head of a zero-indexed linked list and two indices i and j, swaps
the elements at these indices.
*
* Returns the head of the resulting list.
*/
public static ListNode swapElements(ListNode head, int i, int j) {
return null;
}
/**
* Given the head of a singly linked list, reverse the list, and return the
reversed list.
*/
public static ListNode reverseList(ListNode head) {
return null;
}
/**
* Given the head of a singly linked list, returns the middle node of the
linked list.
*
* If there are an even number of elements -- and thus two middle nodes --
returns the second middle node.
*/
public static ListNode middleNode(ListNode head) {
return null;
}
}
list node.java code:
/**
* Definition for singly-linked list.
*/
public class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
List utils.java code
/**
* Utilities for singly-linked non-circular lists.
*/
public class ListUtils {
private ListUtils() {}
static ListNode copyList(ListNode list) {
ListNode head = new ListNode(list.val);
ListNode currentNew = head;
ListNode currentOld = list.next;
while(currentOld != null) {
currentNew.next = new ListNode(currentOld.val);
currentNew = currentNew.next;
currentOld = currentOld.next;
}
return head;
}
static void displayList(ListNode list) {
if(list == null) {
System.out.println("[]");
return;
}
StringBuilder sb = new StringBuilder();
sb.append('[');
while(list != null) {
sb.append(list.val);
sb.append(',');
sb.append(' ');
list = list.next;
}
sb.delete(sb.lastIndexOf(","), sb.length());
sb.append(']');
System.out.println(sb);
}
static ListNode arrayToLinkedList(int[] arr) {
if(arr.length == 0)
return null;
ListNode head = new ListNode(arr[0]);
ListNode current = head;
for(int i = 1; i < arr.length; i++) {
current.next = new ListNode(arr[i]);
current = current.next;
}
return head;
}
}
For this lab you will solve a few separate problems that involve linked lists. Some of these
problems are taken from leetcode, but in a few instances are made small changes. TASK 1
display linked lists. TASK 2 Download this starter code: LinkedListPracticeLab.java you are trying
to solve! And when designing your solution you may want to make some drawings of how the
linked lists are being manipulated. TASK 3 the tests. But make sure you include several tests for
each solution, and that you test for "special" or "boundary" cases. Submit: Your version of
LinkedListPracticeLab.java. For each implemented method, a screenshot showing tests for that
method.

More Related Content

Similar to here is the starter code public class LinkedListPracticeLab.pdf (20)

PDF
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
footstatus
 
PDF
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
PDF
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
PDF
using the single linked list code written in the class or in the lab,.pdf
RBMADU
 
PDF
practice of using and manipulating a doubly linked list and (2) prac.pdf
rd1742
 
PDF
Complete in JavaCardApp.javapublic class CardApp { private.pdf
MAYANKBANSAL1981
 
PDF
Use the singly linked list class introduced in the lab to implement .pdf
sales87
 
PDF
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
PDF
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
PDF
Describe an algorithm for concatenating two singly linked lists L and.pdf
deepak596396
 
PDF
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
JamesPXNNewmanp
 
PDF
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
PDF
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
PDF
Linked List Leetcode - Easy Collections - Interview Questions Java
Sunil Yadav
 
PPTX
Chapter 4 Linked List introduction lessons.pptx
MohamedAhmed686097
 
PDF
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
kingsandqueens3
 
PDF
#include sstream #include linkylist.h #include iostream.pdf
aravlitraders2012
 
PDF
Sorted number list implementation with linked listsStep 1 Inspec.pdf
almaniaeyewear
 
PDF
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
fantasiatheoutofthef
 
PDF
Rewrite this code so it can use a generic type instead of integers. .pdf
alphaagenciesindia
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
footstatus
 
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
using the single linked list code written in the class or in the lab,.pdf
RBMADU
 
practice of using and manipulating a doubly linked list and (2) prac.pdf
rd1742
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
MAYANKBANSAL1981
 
Use the singly linked list class introduced in the lab to implement .pdf
sales87
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
deepak596396
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
JamesPXNNewmanp
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
Linked List Leetcode - Easy Collections - Interview Questions Java
Sunil Yadav
 
Chapter 4 Linked List introduction lessons.pptx
MohamedAhmed686097
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
kingsandqueens3
 
#include sstream #include linkylist.h #include iostream.pdf
aravlitraders2012
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
almaniaeyewear
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
fantasiatheoutofthef
 
Rewrite this code so it can use a generic type instead of integers. .pdf
alphaagenciesindia
 

More from geetakannupillai1 (20)

PDF
Hidrojen ba bir elektropozitif hidrojen H atomunun civ.pdf
geetakannupillai1
 
PDF
Hi In SE and under use case diagram we have 4 relationships.pdf
geetakannupillai1
 
PDF
Highlight the correct answer i have tried myself Pleas.pdf
geetakannupillai1
 
PDF
High involvement and low involvement marketing Point Di.pdf
geetakannupillai1
 
PDF
Hi there Can you help me determine the sample and the popul.pdf
geetakannupillai1
 
PDF
help please Please respond to this post by choosing any o.pdf
geetakannupillai1
 
PDF
Hi There Please help me with 1 The python code AND .pdf
geetakannupillai1
 
PDF
Hi Im currently working on my python assignment and Im st.pdf
geetakannupillai1
 
PDF
Hi I need help with just step c of this question The rest.pdf
geetakannupillai1
 
PDF
Hi Experts Could some one please explain with a practical e.pdf
geetakannupillai1
 
PDF
hhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdf
geetakannupillai1
 
PDF
Heteraride st ynetimin rol Soru seenekleri 1 kat.pdf
geetakannupillai1
 
PDF
Herzbergs twofactor theory proposes that A lower wages w.pdf
geetakannupillai1
 
PDF
Herhangi iki i A tr Elektronik Ticarete Girite Kutz tara.pdf
geetakannupillai1
 
PDF
Help with media assessment In April 2022 WarnerMedia Owne.pdf
geetakannupillai1
 
PDF
Here is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdf
geetakannupillai1
 
PDF
Here is two discussion board posts please give me a paragrap.pdf
geetakannupillai1
 
PDF
Here is The code in C language .pdf
geetakannupillai1
 
PDF
Helper T cells with a mutation called CCR5 delta 32 cannot .pdf
geetakannupillai1
 
PDF
Here is the remaining question of the case study Under the .pdf
geetakannupillai1
 
Hidrojen ba bir elektropozitif hidrojen H atomunun civ.pdf
geetakannupillai1
 
Hi In SE and under use case diagram we have 4 relationships.pdf
geetakannupillai1
 
Highlight the correct answer i have tried myself Pleas.pdf
geetakannupillai1
 
High involvement and low involvement marketing Point Di.pdf
geetakannupillai1
 
Hi there Can you help me determine the sample and the popul.pdf
geetakannupillai1
 
help please Please respond to this post by choosing any o.pdf
geetakannupillai1
 
Hi There Please help me with 1 The python code AND .pdf
geetakannupillai1
 
Hi Im currently working on my python assignment and Im st.pdf
geetakannupillai1
 
Hi I need help with just step c of this question The rest.pdf
geetakannupillai1
 
Hi Experts Could some one please explain with a practical e.pdf
geetakannupillai1
 
hhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdf
geetakannupillai1
 
Heteraride st ynetimin rol Soru seenekleri 1 kat.pdf
geetakannupillai1
 
Herzbergs twofactor theory proposes that A lower wages w.pdf
geetakannupillai1
 
Herhangi iki i A tr Elektronik Ticarete Girite Kutz tara.pdf
geetakannupillai1
 
Help with media assessment In April 2022 WarnerMedia Owne.pdf
geetakannupillai1
 
Here is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdf
geetakannupillai1
 
Here is two discussion board posts please give me a paragrap.pdf
geetakannupillai1
 
Here is The code in C language .pdf
geetakannupillai1
 
Helper T cells with a mutation called CCR5 delta 32 cannot .pdf
geetakannupillai1
 
Here is the remaining question of the case study Under the .pdf
geetakannupillai1
 

Recently uploaded (20)

PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
community health nursing question paper 2.pdf
Prince kumar
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 

here is the starter code public class LinkedListPracticeLab.pdf

  • 1. here is the starter code: public class LinkedListPracticeLab { private LinkedListPracticeLab(){} public static void main(String[] args) { // Test all methods here } /** * Given the heads of two sorted linked lists, merges the two lists in a one sorted list. * The list is made by splicing together the nodes of the original two lists, without * creating any new nodes. * * Returns the head of the merged linked list. */ public static ListNode mergeLists(ListNode head1, ListNode head2) { return null; } /** * Given the head of a sorted linked list, deletes all duplicates such that each element appears only once. * * Returns the head of the resulting linked list, which is still sorted. */ public static ListNode deleteDuplicates(ListNode head) { return null; } /** * Given the head of a linked list and an integer val, removes all the nodes of the linked list that has * Node.val == val. * * Returns the head of the resulting list. */ public static ListNode removeElements(ListNode head, int val) { return null; } /** * Given the head of a zero-indexed linked list and two indices i and j, swaps the elements at these indices. * * Returns the head of the resulting list.
  • 2. */ public static ListNode swapElements(ListNode head, int i, int j) { return null; } /** * Given the head of a singly linked list, reverse the list, and return the reversed list. */ public static ListNode reverseList(ListNode head) { return null; } /** * Given the head of a singly linked list, returns the middle node of the linked list. * * If there are an even number of elements -- and thus two middle nodes -- returns the second middle node. */ public static ListNode middleNode(ListNode head) { return null; } } list node.java code: /** * Definition for singly-linked list. */ public class ListNode { int val; ListNode next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val; this.next = next; } } List utils.java code /** * Utilities for singly-linked non-circular lists. */ public class ListUtils { private ListUtils() {} static ListNode copyList(ListNode list) { ListNode head = new ListNode(list.val); ListNode currentNew = head;
  • 3. ListNode currentOld = list.next; while(currentOld != null) { currentNew.next = new ListNode(currentOld.val); currentNew = currentNew.next; currentOld = currentOld.next; } return head; } static void displayList(ListNode list) { if(list == null) { System.out.println("[]"); return; } StringBuilder sb = new StringBuilder(); sb.append('['); while(list != null) { sb.append(list.val); sb.append(','); sb.append(' '); list = list.next; } sb.delete(sb.lastIndexOf(","), sb.length()); sb.append(']'); System.out.println(sb); } static ListNode arrayToLinkedList(int[] arr) { if(arr.length == 0) return null; ListNode head = new ListNode(arr[0]); ListNode current = head; for(int i = 1; i < arr.length; i++) { current.next = new ListNode(arr[i]); current = current.next; } return head; } } For this lab you will solve a few separate problems that involve linked lists. Some of these problems are taken from leetcode, but in a few instances are made small changes. TASK 1 display linked lists. TASK 2 Download this starter code: LinkedListPracticeLab.java you are trying to solve! And when designing your solution you may want to make some drawings of how the linked lists are being manipulated. TASK 3 the tests. But make sure you include several tests for
  • 4. each solution, and that you test for "special" or "boundary" cases. Submit: Your version of LinkedListPracticeLab.java. For each implemented method, a screenshot showing tests for that method.