Run lools ?indow Help ,?G Mainjava >? @ew04Ex04 ×|| EW04Ex08 × ava × isPali 7Jiw
ID: 3914933 • Letter: R
Question
Run lools ?indow Help ,?G Mainjava >? @ew04Ex04 ×|| EW04Ex08 × ava × isPali 7Jiwon Woo //E?04 //cs 211 4 117/17/2018 6 package com. companyi ??mport java .util.zinkedL?st; import java.util.Queue: 10 ??mport java .util.Stack; 12public class CopyStack t 13 14 public static stack copystack (stack stack) 15 16 17 18 19 20 21 Queue queuenew LinkedList ): Stack nevstack-new Stack )i while lstack.iaEmpty) (stack.pop )) while (tqueue.isempty)) (queue. remove )): while (Istack.isEmpty)) 23 24 25 26 27 28 queue, add (atack.pop)) while (Iqueue.isEmpty)) ( intiueue. remove (0 stack.add (i); 30 31 32 return newstack; public static void main (Stringtl arga) Stack stack new Stack tack.push item: 5) stack.push( item: 3) stack.push item: 12) 35 36 38 39 40 item: 1) system.out.println ("Original stack") CopyStack copyStackoExplanation / Answer
Possible solution to the problem
Explanation
Since you didn't mentioned the type while creating queue hence the queue is assuming the type of elements as an Object. So, It is necessary to tell the compiler that you are dealing with an int type whenever you encounter that error.
You can also correct the error by declaring the queue and mentioning its type in following way
Queue<Integer> queue = new LinkedList<Integer>();
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.