Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//trying to make stack implemented by LinkedList which takes input from user via console(i dont know if i am doing this right) and pops the

//trying to make stack implemented by LinkedList which takes input from user via console(i dont know if i am doing this right) and pops the word after "*" or pushes(item) if there is no "*"

example input: Hey there * how * are * you * doing there

//Disregard use of StdIn and StdOut style I have to use them for this exercise.

public class Practice { private Node first= null; private int N= 0; private class Node { private Item item; private Node next; } public boolean isEmpty() { return (N==0);} public void push(Item item) { Node second= first; first= new Node(); first.item= item; first.next= second; N++; } public Item pop() { Item item= first.item; first= first.next; N--; return item; } public int size() { return N; }

public static void main(String[] args) { Practice stack= new Practice(); while(!StdIn.isEmpty()) { String item= StdIn.readString(); if(item.equals("*")) System.out.print(stack.pop()+ " "); else stack.push(item); } StdOut.println(); }

}

//Explanations required about StdIn and use of console for input : Best regards

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

How much information do we consciously attend to at once?

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago