博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
List, Stack, and Queue
阅读量:6985 次
发布时间:2019-06-27

本文共 2779 字,大约阅读时间需要 9 分钟。

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.

转载地址:http://rbqpl.baihongyu.com/

你可能感兴趣的文章
解决安装rrdtool遇到的一个问题
查看>>
linux启动过程
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
xmlUtil 解析 创建
查看>>
我的友情链接
查看>>
linux 命令(3)echo
查看>>
Nginx基础入门之nginx基础配置项介绍(2)
查看>>
一次详细全面的***报告
查看>>
c# 三种异步编程模型EAP(*)、 APM(*)和 TPL
查看>>
deepin-安装问题:unable to find a medium containing a live file
查看>>
用 Hasor 谈一谈MVC设计模式
查看>>
IE 条件注释
查看>>
Windows热键注册(反汇编方法 查看win32api 原理)
查看>>
UNREFERENCED_PARAMETER的作用
查看>>
PHP计算表达式-栈
查看>>
IBATIS中关于iterate"$"与"#"的应用
查看>>
为什么要将对象序列化
查看>>
新增网址/网页 截图api[增加安全防护本接口已停用]源码可下载
查看>>
SpringMVC+Hibernate +MySql+ EasyUI实现POI导出Excel(二)
查看>>