Question: 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

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!