Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you make a java code that translates this exact code of a singly linked list to perform the following operations. for the nodes, use
Can you make a java code that translates this exact code of a singly linked list to perform the following operations.
for the nodes, use integers and call each of the following functions from main.
put the node functions into a separate class from main.
ListAppend(list, newNode) { if (listhead == null) { // List empty listhead = newNode listtail = newNode } else{ listtailnext = newNode listtail = newNode } }
ListPrepend(list, newNode) { if (listhead == null) { // list empty listhead = newNode listtail = newNode } else { newNodenext = listhead listhead = newNode } }
ListInsertAfter(list, curNode, newNode) { if (listhead == null) { // List empty listhead = newNode listtail = newNode } else if (curNode == listtail) { // Insert after tail listtailnext = newNode listtail = newNode } else { newNodenext = curNodenext curNodenext = newNode } }
ListRemoveAfter(list, curNode) { // Special case, remove head if (curNode is null && listhead is not null) { sucNode = listheadnext listhead = sucNode if (sucNode is null) { // Removed last item listtail = null } } else if (curNodenext is not null) { sucNode = curNodenextnext curNodenext = sucNode if (sucNode is null) { // Removed tail listtail = curNode } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started