List, Stack, and Queue

From:《Data Structures and Algorithm Analysis in C++》 chapter 3This chapter discusses three of the most simple and basic data structures.

I will :


* Introduce the concept of Abstract Data Types.
* Show how to efficiently perform operatioins on lists.
* Introduce the stack ADT
* Introduce the queue ADT
1. Abstract Data Types (ADTs)An ADT is a set of objects together with a set of operation.
* Object : such as list, set, graphs, integer, real, boolean...
* Operation: such as find, remove, insert, get....
The C++ class allows for the implementation of ADTs, with appropriate hiding of implementatioin details.There is no rule telling us which operations must be supported for each ADT; this is a design decision.2. The List ADTwe will deal with a general list of the form A0,A1,A2...AN-1;we say the size of list is N, we will canll the special list of size 0 an empty list.For any list except the empty list, we say that Ai follows Ai-1(i < N )and that Ai-1 precedes Ai (i > 0). The first element of the list is A0,and the last element is An-1.2.1 Simple Array Implementation of ListsAll of these instructions can be implemented just by using an array. Although arrays are created with a fixed capacity.
* printList is carried out in linear time;
* findKth takes constant time;
* insertion and deletion are potentially expensive, depending on where the insertions and deletetions.
2.2 Simple Linked ListsIn order to avoid the linear cost of insertion and deletion, we need to ensure that the list is not stored contiguously, since otherwise entire parts of thte list will need to be moved.The linked list consists of a series of nodes, which are not necessarily adjacent in memory. Each node contains the element and a link to a node containing its successor. we call this the next link. The last cell's next link points to NULL.
* printList() and find(x) take a linear-time;
* remove() take a constant time;
* insert() take a constant time.
3. The Stack ADT3.1 Stack ModelA stack is a list with the restriction that insertions and deletions can be performed in only one position, namely, the end of the list, called the top.There are two main operations:
* Push : insert an element into stack;
* Pop : delete the most recently inserted element.
A pop or top on an empty stack is generally considered an error in the stack ADT.On the other hand, running out of space when performing a push is an implementation limit but not an ADT Error.Stack is sometimes known as LIFO(last in , first out) lists.4. The Queue ADTLike stacks, queues are list. with a queue, however, insertion is done at one end, whereas deletion is erformed at the other hand.The basic operatioins on a queue :
* enqueue : inserts an element at the end of the list;
* dequeue : deletes the element at the start of the list.
原文链接: https://www.cnblogs.com/loveyakamoz/archive/2012/11/14/2769888.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/69394

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午1:46
下一篇 2023年2月9日 下午1:47

相关推荐