Stack and Queue(1) - Abstract Data Type(ADT Abstraction is...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Abstract Data Type (ADT) Abstraction is the process to reduce the information content of a concept, typically to retain only information which is relevant for a particular purpose. In computer science, abstraction is the process by which data and programs are defined with a representation similar in form to its meaning (semantics), while hiding away the implementation details . In OO-programming, we try to separate the logical properties of an object from its internal implementation details. For example, the standardized user interface of an Android phone is a logical property of the device. The construction of the physical Android phone is the implementation details. From the point of view of the user, you only need to know the logical property (i.e. the user interface) of the device when you are using the phone, you don’t need to know its internal implementation details. ADT is a tool that allows the programmer to separate the logical properties of a data structure from its implementation details. An ADT has 3 components: name of the ADT, called the type name the set of values belonging to the ADT, called the domain the set of operations on the data (corresponds to the member functions in the implementation)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Abstract Data Type : Stack A stack is a list of homogeneous elements in which the addition and deletion of elements occur only at one end, called the top of the stack. A stack is also called a Last In First Out (LIFO) data structure. Operations on a stack: initialize : initialize the stack to an empty state size : determine the number of elements in the stack empty : determine if the stack is empty top : retrieve the value of the top element push : insert element at the top of stack pop : remove top element In C++, we can define an ADT using an abstract class. In our discussion, I will try to follow the notations used in the C++ STL (Standard Template Library). template<class Type> class stackADT { public: virtual void initialize() = 0 ; //pure virtual function //remark: the initialize() function is not part of the // C++ STL. The initialization can be taken care // of by the constructor. virtual int size() const = 0; virtual bool empty() const = 0; virtual Type & top() const = 0; //return lvalue reference //of the top element virtual void push(const Type& item) = 0; //lvalue reference virtual void push( Type && item) = 0; //rvalue reference virtual void pop() = 0; //Note that in the C++ STL, the pop function does not //return the (old) top element that is removed. //Remark: in Java, the pop method of the class Stack // will return the removed element. }
Image of page 2
3 Remarks: In the textbook, the author includes a function full() in the stackADT . The function full() returns true if the stack is full. However, full() is not part of the stack class in C++ STL. It is not required if the stack is implemented using linked list.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern