List, Stack, and Queue

From:《Data Structures and Algorithm Analysis in C++》 chapter 3
This 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 ADT
     we 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 Lists
     All 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 Lists 
     In 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 ADT
3.1 Stack Model
     A 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 ADT
     Like 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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值