Java: I just need the 4 code segments to implement stacks using a DynamicArray generic type : } } }

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Java: I just need the 4 code segments to implement stacks using a DynamicArray generic type : } } }

Post by answerhappygod »

Java: I just need the 4 code segments to
implement stacks using a DynamicArray generic
type <E>:
Java I Just Need The 4 Code Segments To Implement Stacks Using A Dynamicarray Generic Type E 1
Java I Just Need The 4 Code Segments To Implement Stacks Using A Dynamicarray Generic Type E 1 (120.09 KiB) Viewed 59 times
}
}
}
1 // PROGRAMMER: John Doe 2 public class DynamicStack<E> 3 { 4 // INSTANCE VARIABLES DynamicArray<E> stack; 6 7 // CONSTRUCTORS 8 public Dynamic Stack() 9 { 10 stack = new DynamicArray<E>(); 11 } 12 13 public DynamicStack(E element) 14 15 // ENTER CODE HERE ... 16 } 17 18 public DynamicStack(E[] array) 19 20 // ENTER CODE HERE 21 22 } 23 24 // INSTANCE METHODS 25 public void push(E element) 26 { stack.addToEnd (element); 28 } 29 30 public Epop) 31 { 32 // ENTER CODE HERE 33 { 35 throw new RuntimeException("Empty Stack"); 36 } 37 return( stack.remove(stack.getNumberOfElements () - 1) ); 38 } 39 40 public E peek) 41 { 42 // ENTER CODE HERE ... 43 { 44 throw new RuntimeException("Empty Stack"); 45 } 46 return( stack.get( stack.getNumberOfElements() - 1) ); 47 } 48 49 public boolean empty() 50 51 if(stack.getNumberOfElements() == 0) 52 { 53 return(true); 54 55 else 56 { 57 return(false); }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply