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?
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.Sign up to join this community
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 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
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.