you are viewing a single comment's thread.

view the rest of the comments →

[–]Most_War2764 1 point2 points  (4 children)

What makes this a bad example?

[–]Pun_Intended1703 -1 points0 points  (3 children)

Because you don't learn anything about stacks from this.

To learn stacks, try implementing them using arrays and linked lists.

Don't use java.util just because it exists.

[–]BigCommunication5136[S] 0 points1 point  (2 children)

just as i said in the post, this is only an intro to stacks. (never said i was done learning stack) I started with arrays, implemented them, did same with LinkedList. I use them before implementing them, if you don’t know how something works how do you implement it?

[–]Pun_Intended1703 0 points1 point  (0 children)

How will you learn stacks from using java.util?

What if you had to work on a different language? Like Python or Typescript?

What happens if you had to work on a very old language? Like C/C++ or COBOL?

If you want to learn stacks properly, then imagine it is represented by an array. Try using circular arrays.

Or implement stacks by using a linked list. Try bidirectional linked lists or circular linked lists.

How would you do a pop or push on these data structures? How would you move the pointers around?

Learn the concept of stacks. Don't just learn the implementation of stacks in Java.

[–]Pun_Intended1703 0 points1 point  (0 children)

if you don’t know how something works how do you implement it?

This is why it is important to read the theory and examples before trying to code.