38 Lab Inventory Linked Lists Insert Particular Location Given Main Inventory Class Define Q37147089

3.8 LAB: Inventory (linked lists: insert at a particularlocation)

Given main() in the Inventory class, define an insertAtFront()method in the InventoryNode class that inserts items at the frontof a linked list (after the dummy head node).

Ex. If the input is

4plates 100spoons 200cups 150forks 200

the output is

200 forks150 cups200 spoons100 plates

The following has been provided for us:

THIS CLASS IS READ ONLY!!!! ALL CODE NEEDS TO BE WRITTENIN NEXT CLASS.

import java.util.Scanner;

public class Inventory {
public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);

InventoryNode headNode;
InventoryNode currNode;
InventoryNode lastNode;

String item;
int numberOfItems;
int i;

// Front of nodes list   
headNode = new InventoryNode();
lastNode = headNode;

int input = scnr.nextInt();

for(i

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.