What is the difference between the enqueue () method in LinkedQueue and the push () method in LinkedStack?

  • And where are these containers defined? - Vlad from Moscow

1 answer 1

They do the same thing, in fact.

public void push (T element){ LinearNode<T> temp = new LinearNode<T> (element); temp.setNext(top); top = temp; count++; } public void enqueue (T element){ LinearNode<T> node = new LinearNode<T>(element); if (isEmpty()) front = node; else rear.setNext (node); rear = node; count++; } 

The only difference is where the insertion takes place. Why different methods are called is a mystery.

  • Because enqueue is put in the queue. And traditionally they put in the stack, place, push it in - push. For different concepts, different verbs, different actions to show the very essence of what is happening, so that everything would be clear even to a fool. - Sergey
  • @Sergey yes it seems from the class name is clear and so = \ - Suvitruf
  • In fact, the enti classes are not needed. This is just a List, with copies of the add method, called differently. We do not need the same methods or the same classes. List # add our everything! - Sergey