Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java: Neatbeans project how to insert a node in the list before a specified elem

ID: 3759156 • Letter: J

Question

Java: Neatbeans project

how to insert a node in the list before a specified element

how to insert a node in the list after a specified element

how to append a node to the list:add a node after the last element in the list

how to prepend a node to the list: add a node as the new head of the list

The data file looks like the following:

K1110
Bruce
Osborne
Administrative Services Manager
K1111
Edgar
Stevenson
Advertising Manager
K1112
Oscar
Brock
Assistant Director
K1113
Jermaine
Hubbard
Chief Executive Office
K1114
Fredrick
Ellis
Chief Operations Office

Explanation / Answer

1)
void Stack::stackA(Item *q,Item *q1)
{
Item* item = this->first;
if (item == q)
{
this->first = q1;
q1->next = q;
return;
}
while (item != null)
{
if (item->next == q)
{
item->next = q1;
q1->next = q;
break;
}
item = item->next;
}
}

3)

public void prepend(String item)
{
if (head == null)
{
head = tail = new Node(item, null);
curr = head;
}
else
{
head = new Node(item, head);
curr = head;
}
}

3)
public void append(String item)
{
if (head == null)
{
head = tail = new Node(item, null);
curr = tail;
}
else
{
tail.next = new Node(item, null);
tail = tail.next;
curr = tail;
}
}
public void add(String item)
{
if (curr != null)
{
Node newNode = new Node(item, curr.next);
curr.next = newNode;
curr = newNode;
}
else
{
head = tail = new Node(item, null);
curr = head;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote