Ok, I dont understand whats the difference between: write code for stack operations and write adt for stack operations?

lets say the operation is push() and pop(). So what different code is to be written for adt?

  • $\begingroup$ Depends. What about completeness (isEmpty())? What about infrastructure (equals(), C++&co.: new and dispose())? (begineer?) $\endgroup$
    – greybeard
    Commented Dec 4, 2020 at 8:30

1 Answer 1


Code is literal programming code (be it C/C++, Java, Python, etc.). We can agree the code will be completely different between languages. In addition, if you are implementing a stack, then you have modify your code depending on what underlying data structure you're using to store the data (c style arrays in C, ArrayLists in Java, etc.).

ADT is a way to express the basic operations of the data type independently from the code (from any programming language). This leads to pseudocode.

For instance, a queue ADT might have the following functions: enqueue, dequeue, front. The enqueue function takes data and adds it to the back of the queue; the dequeue function removes data from the front of the queue and returns it; finally the front function simply returns the first data in the queue but does not remove it.

The above is the most basic queue ADT, but you could have other functions like back, isEmpty, or even something weird like thirdPlaceInQueue. It all depends on what your needs are. Be careful though, giving too much functionality may lead to a different ADT. For instance, if you gave a queue ADT the ability to add to the front and remove from the back, you would then have a deque ADT.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.