日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

List, Stack, and Queue

發布時間:2024/9/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.

總結

以上是生活随笔為你收集整理的List, Stack, and Queue的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。