思维是什么意思| 最大的狗是什么品种| 隅读什么| 什么动物没有天敌| 天启是什么意思| 阑尾粪石是什么意思| 子宫内膜囊性增生是什么意思| 10.30什么星座| 脚指甲发白是什么原因| 俞是什么意思| 什么都不想做| 什么的北京| 什么是淋巴| 阴部痒痒的是什么原因| 轭是什么意思| 甲亢吃什么药好| 什么是排卵期怎么计算| 兔死狗烹是什么意思| 埃及是什么人种| 月亮的肚子指的是什么| 胃烧心是什么感觉| 辰砂和朱砂有什么区别| tg医学上是什么意思| 你的生命有什么可能| 孕激素是什么| 什么水果清肝火| 烧头七有什么讲究| 透明的什么| 女人左下腹部疼痛什么原因| 怀孕第一个月最怕什么| 支原体阳性什么意思| bmi什么意思| 商鞅变法是什么时期| 18年是什么年| 莴笋不能和什么一起吃| 吃什么治疗阳痿| 什么原因造成高血压| no.是什么意思| 什么是外阴| 女性腰疼去医院挂什么科| 蝉吃什么食物| 9是什么生肖| 脚气用什么药| 什么情况下会宫外孕| 天秤座女和什么星座最配| 42是什么生肖| 处暑吃什么| food什么意思| 是什么元素| cpi什么意思| 济州岛有什么好玩的| 吃什么能降尿酸| 前胸后背长痘痘用什么药| 吃什么补阳气最快| 阴茎插入阴道什么感觉| 什么蛇有毒| cache是什么意思| 追悔莫及什么意思| 795是什么意思| 肌苷是什么| dr是什么检查项目| 咬肌疼是什么原因| 11月28是什么星座| 总是口渴是什么原因| 谷草转氨酶偏低是什么原因| 肉痣长什么样子图片| 宫颈肥大伴纳氏囊肿是什么意思| 耳闷耳堵是什么原因引起的| 务农是什么意思| 强迫症是什么意思| 肝s5是什么意思| 乳糖醇是什么| 吃红薯有什么好处和坏处| 后背疼是什么病的前兆| 身上没力气没劲是什么原因| 阿托品是什么| 梦见狗追我是什么意思| 一身傲骨是什么意思| 鼠和什么属相最配对| 小孩说话不清楚挂什么科| 方得始终什么意思| 数字8五行属什么| brunch是什么意思| 农历九月是什么月| 哺乳期吃什么水果好| 大骨头属于什么垃圾| 有尿意但是尿不出来是什么原因| 为什么美国支持以色列| 血脂稠吃什么食物好| 女生什么时候最想要| 柠檬不能和什么一起吃| 胎儿生物物理评分8分什么意思| 室缺是什么意思| 百鸟归巢什么意思| 褒义词和贬义词是什么意思| 鼻窦炎用什么药效果最好| 鸡蛋补充什么营养| 腿外侧是什么经络| 言字五行属什么| 陈真属什么生肖| 孕妇感染弓形虫有什么症状| 洱海为什么叫洱海| 右眼皮跳是什么预兆女| 什么人不能喝咖啡| 天天喝白酒对身体有什么危害| 弥陀是什么意思| sds是什么| 竹肠是什么部位| 人出现幻觉是什么原因| 电脑为什么打不开| 胡萝卜炒什么好吃| nokia是什么牌子的手机| 箨是什么意思| 腹部ct平扫能检查出什么| 手热是什么原因| doris什么意思| 拉肚子吃什么益生菌| 为什么新生儿会有黄疸| 吃什么水果败火| 做梦车丢了有什么预兆| 手麻木是什么引起的| 手上月牙代表什么| 擦伤用什么药好得快| 宇五行属什么| 银杏果什么时候成熟| 青提是什么| 水杯什么品牌好| 空囊是什么原因造成的| 什么鱼适合清蒸| 甲状腺结节吃什么药好| 扁桃体发炎引起的发烧吃什么药| 牙龈炎吃什么药| 玉米须能治什么病| 胆挂什么科| 涤纶是什么| 一直发烧不退是什么原因| 什么是新陈代谢| 龟头是什么意思| 妮是什么意思| 土耳其说什么语言| 肾炎康复片主要是治疗什么| 液氧是什么| 4ever是什么意思| 什么是腐女| 比目鱼是什么鱼| 高温丝假发是什么材质| 猩红热是什么| 三个箭头朝下是什么牌子| 西藏有什么大学| 包皮溃烂用什么药| tmp是什么药| 姜虫咬人有什么症状| 经期吃什么食物比较好| orange是什么颜色| 布谷鸟什么时候叫| 感谢老师送什么花| 料酒可以用什么代替| 肺部炎症用什么药最好| 人和是什么意思| 兰州人为什么要戴头巾| 白细胞0是什么意思| 什么人容易老年痴呆| 上海市长什么级别| 大人睡觉流口水是什么原因引起的| 山药不能和什么一起吃| 为什么外阴老是长疖子| 腊月初八是什么日子| 内外兼修是什么意思| logo是什么| 血栓挂什么科| 7月27号是什么星座| 梦见空棺材是什么意思| 2019年出生属什么生肖| 化疗与放疗有什么区别| 贲门ca是什么意思| 药石是什么意思| 鬼代表什么数字| 宫颈糜烂有什么症状和现象| 个性是什么意思| 咒语是什么意思| 什么是全麦面包| 腔隙性脑梗死吃什么药| 慢性非萎缩性胃炎伴糜烂是什么意思| 菠萝蜜什么季节成熟| 筋膜炎吃什么药最有效| 脚脱皮用什么药| 头疼喝什么药| 璎珞是什么意思| 属马是什么命| 狗不吃饭是什么原因| 腋臭看什么科| ootd什么意思| 新加坡用什么货币| 心火旺吃什么中药| 化险为夷的夷什么意思| 吃什么不便秘| 天蝎座是什么象星座| 什么于怀| 父亲节做什么手工| 有缘无分什么意思| 梦见狗是什么预兆| ci是什么意思| 阴蒂在什么位置| 缘故的故是什么意思| 指腹脱皮是什么原因| 大便干燥吃什么药| 钡餐检查能查出什么| 酊是什么意思| 吃什么养胃又补胃| 捐精有什么要求| 不丹为什么不和中国建交| 自由基是什么意思| 怀孕后壁和前壁有什么区别| 女人是男人的什么| 51是什么意思| 肝火旺是什么原因引起的| 结肠炎吃什么药最见效| 丝瓜可以炒什么| 什么是木薯粉| 啤酒有什么牌子| 大学生村官是什么编制| rag什么意思| 修复胃粘膜吃什么药| ivf是什么意思| 父亲节送爸爸什么| 重视是什么意思| 人黑穿什么颜色的衣服好看| 晨咳是什么原因引起的| 硝苯地平是什么药| 什么的原始森林| 鱿鱼不能和什么一起吃| 想字五行属什么| 什么是腹式呼吸的正确方法| 白色虫子是什么虫图片| epa是什么| 1226是什么星座| 吃什么降三高最快| 口腔溃疡需要补充什么维生素| 检查耳朵挂什么科| 寻麻疹是什么原因引起的| noxa20是什么药| 家里为什么会有壁虎| 梦见自己找工作是什么意思| 例假淋漓不尽是什么原因造成的| 做试管前需要检查什么项目| 肾结石术后吃什么食物最好| 消防大队长是什么级别| 去鱼腥味最好的方法是什么| 低压低什么原因| 来月经前有什么症状| 脑供血不足吃什么药好得快| 鹦鹉拉肚子吃什么药| 肚子总胀气是什么原因| 端午节都吃什么菜好| emba是什么意思| 墨水用什么能洗掉| 美缝剂什么牌子的好| 小白龙叫什么名字| 养肝吃什么食物| 无偿是什么意思| 心电图低电压什么意思| 百香果什么时候开花结果| 纵隔占位是什么意思| 大步向前走永远不回头是什么歌| 百度

丰胸吃什么食物有效果

百度 ”  一直以来,我国都高度重视各民族文化遗产的保护,许多少数民族优秀传统文化得到了传承和弘扬。

In computer science, an abstract data type (ADT) is a mathematical model for data types, defined by its behavior (semantics) from the point of view of a user of the data, specifically in terms of possible values, possible operations on data of this type, and the behavior of these operations. This mathematical model contrasts with data structures, which are concrete representations of data, and are the point of view of an implementer, not a user. For example, a stack has push/pop operations that follow a Last-In-First-Out rule, and can be concretely implemented using either a list or an array. Another example is a set which stores values, without any particular order, and no repeated values. Values themselves are not retrieved from sets; rather, one tests a value for membership to obtain a Boolean "in" or "not in".

ADTs are a theoretical concept, used in formal semantics and program verification and, less strictly, in the design and analysis of algorithms, data structures, and software systems. Most mainstream computer languages do not directly support formally specifying ADTs. However, various language features correspond to certain aspects of implementing ADTs, and are easily confused with ADTs proper; these include abstract types, opaque data types, protocols, and design by contract. For example, in modular programming, the module declares procedures that correspond to the ADT operations, often with comments that describe the constraints. This information hiding strategy allows the implementation of the module to be changed without disturbing the client programs, but the module only informally defines an ADT. The notion of abstract data types is related to the concept of data abstraction, important in object-oriented programming and design by contract methodologies for software engineering.[1]

History

edit

ADTs were first proposed by Barbara Liskov and Stephen N. Zilles in 1974, as part of the development of the CLU language.[2] Algebraic specification was an important subject of research in CS around 1980 and almost a synonym for abstract data types at that time.[3] It has a mathematical foundation in universal algebra.[4]

Definition

edit

Formally, an ADT is analogous to an algebraic structure in mathematics,[5] consisting of a domain, a collection of operations, and a set of constraints the operations must satisfy.[6] The domain is often defined implicitly, for example the free object over the set of ADT operations. The interface of the ADT typically refers only to the domain and operations, and perhaps some of the constraints on the operations, such as pre-conditions and post-conditions; but not to other constraints, such as relations between the operations, which are considered behavior. There are two main styles of formal specifications for behavior, axiomatic semantics and operational semantics.[7]

Despite not being part of the interface, the constraints are still important to the definition of the ADT; for example a stack and a queue have similar add element/remove element interfaces, but it is the constraints that distinguish last-in-first-out from first-in-first-out behavior. The constraints do not consist only of equations such as fetch(store(S,v))=v but also logical formulas.

Operational semantics

edit

In the spirit of imperative programming, an abstract data structure is conceived as an entity that is mutable—meaning that there is a notion of time and the ADT may be in different states at different times. Operations then change the state of the ADT over time; therefore, the order in which operations are evaluated is important, and the same operation on the same entities may have different effects if executed at different times. This is analogous to the instructions of a computer or the commands and procedures of an imperative language. To underscore this view, it is customary to say that the operations are executed or applied, rather than evaluated, similar to the imperative style often used when describing abstract algorithms. The constraints are typically specified in prose.

Auxiliary operations

edit

Presentations of ADTs are often limited in scope to only key operations. More thorough presentations often specify auxiliary operations on ADTs, such as:

  • create(), that yields a new instance of the ADT;
  • compare(s, t), that tests whether two instances' states are equivalent in some sense;
  • hash(s), that computes some standard hash function from the instance's state;
  • print(s) or show(s), that produces a human-readable representation of the instance's state.

These names are illustrative and may vary between authors. In imperative-style ADT definitions, one often finds also:

  • initialize(s), that prepares a newly created instance s for further operations, or resets it to some "initial state";
  • copy(s, t), that puts instance s in a state equivalent to that of t;
  • clone(t), that performs screate(), copy(s, t), and returns s;
  • free(s) or destroy(s), that reclaims the memory and other resources used by s.

The free operation is not normally relevant or meaningful, since ADTs are theoretical entities that do not "use memory". However, it may be necessary when one needs to analyze the storage used by an algorithm that uses the ADT. In that case, one needs additional axioms that specify how much memory each ADT instance uses, as a function of its state, and how much of it is returned to the pool by free.

Restricted types

edit

The definition of an ADT often restricts the stored value(s) for its instances, to members of a specific set X called the range of those variables. For example, an abstract variable may be constrained to only store integers. As in programming languages, such restrictions may simplify the description and analysis of algorithms, and improve its readability.

Aliasing

edit

In the operational style, it is often unclear how multiple instances are handled and if modifying one instance may affect others. A common style of defining ADTs writes the operations as if only one instance exists during the execution of the algorithm, and all operations are applied to that instance. For example, a stack may have operations push(x) and pop(), that operate on the only existing stack. ADT definitions in this style can be easily rewritten to admit multiple coexisting instances of the ADT, by adding an explicit instance parameter (like S in the stack example below) to every operation that uses or modifies the implicit instance. Some ADTs cannot be meaningfully defined without allowing multiple instances, for example when a single operation takes two distinct instances of the ADT as parameters, such as a union operation on sets or a compare operation on lists.

The multiple instance style is sometimes combined with an aliasing axiom, namely that the result of create() is distinct from any instance already in use by the algorithm. Implementations of ADTs may still reuse memory and allow implementations of create() to yield a previously created instance; however, defining that such an instance even is "reused" is difficult in the ADT formalism.

More generally, this axiom may be strengthened to exclude also partial aliasing with other instances, so that composite ADTs (such as trees or records) and reference-style ADTs (such as pointers) may be assumed to be completely disjoint. For example, when extending the definition of an abstract variable to include abstract records, operations upon a field F of a record variable R, clearly involve F, which is distinct from, but also a part of, R. A partial aliasing axiom would state that changing a field of one record variable does not affect any other records.

Complexity analysis

edit

Some authors also include the computational complexity ("cost") of each operation, both in terms of time (for computing operations) and space (for representing values), to aid in analysis of algorithms. For example, one may specify that each operation takes the same time and each value takes the same space regardless of the state of the ADT, or that there is a "size" of the ADT and the operations are linear, quadratic, etc. in the size of the ADT. Alexander Stepanov, designer of the C++ Standard Template Library, included complexity guarantees in the STL specification, arguing:

The reason for introducing the notion of abstract data types was to allow interchangeable software modules. You cannot have interchangeable modules unless these modules share similar complexity behavior. If I replace one module with another module with the same functional behavior but with different complexity tradeoffs, the user of this code will be unpleasantly surprised. I could tell him anything I like about data abstraction, and he still would not want to use the code. Complexity assertions have to be part of the interface.

—?Alexander Stepanov[8]

Other authors disagree, arguing that a stack ADT is the same whether it is implemented with a linked list or an array, despite the difference in operation costs, and that an ADT specification should be independent of implementation.

Examples

edit

Abstract variable

edit

An abstract variable may be regarded as the simplest non-trivial ADT, with the semantics of an imperative variable. It admits two operations, fetch and store. Operational definitions are often written in terms of abstract variables. In the axiomatic semantics, letting   be the type of the abstract variable and   be the type of its contents, fetch is a function   and store is a function of type  . The main constraint is that fetch always returns the value x used in the most recent store operation on the same variable V, i.e. fetch(store(V,x)) = x. We may also require that store overwrites the value fully, store(store(V,x1),x2) = store(V,x2).

In the operational semantics, fetch(V) is a procedure that returns the current value in the location V, and store(V, x) is a procedure with void return type that stores the value x in the location V. The constraints are described informally as that reads are consistent with writes. As in many programming languages, the operation store(V, x) is often written Vx (or some similar notation), and fetch(V) is implied whenever a variable V is used in a context where a value is required. Thus, for example, VV + 1 is commonly understood to be a shorthand for store(V,fetch(V) + 1).

In this definition, it is implicitly assumed that names are always distinct: storing a value into a variable U has no effect on the state of a distinct variable V. To make this assumption explicit, one could add the constraint that:

  • if U and V are distinct variables, the sequence { store(U, x); store(V, y) } is equivalent to { store(V, y); store(U, x) }.

This definition does not say anything about the result of evaluating fetch(V) when V is un-initialized, that is, before performing any store operation on V. Fetching before storing can be disallowed, defined to have a certain result, or left unspecified. There are some algorithms whose efficiency depends on the assumption that such a fetch is legal, and returns some arbitrary value in the variable's range.

Abstract stack

edit

An abstract stack is a last-in-first-out structure, It is generally defined by three key operations: push, that inserts a data item onto the stack; pop, that removes a data item from it; and peek or top, that accesses a data item on top of the stack without removal. A complete abstract stack definition includes also a Boolean-valued function empty(S) and a create() operation that returns an initial stack instance.

In the axiomatic semantics, letting   be the type of stack states and   be the type of values contained in the stack, these could have the types  ,  ,  ,  , and  . In the axiomatic semantics, creating the initial stack is a "trivial" operation, and always returns the same distinguished state. Therefore, it is often designated by a special symbol like Λ or "()". The empty operation predicate can then be written simply as   or  .

The constraints are then pop(push(S,v))=(S,v), top(push(S,v))=v,[9] empty(create) = T (a newly created stack is empty), empty(push(S, x)) = F (pushing something into a stack makes it non-empty). These axioms do not define the effect of top(s) or pop(s), unless s is a stack state returned by a push. Since push leaves the stack non-empty, those two operations can be defined to be invalid when s = Λ. From these axioms (and the lack of side effects), it can be deduced that push(Λ, x) ≠ Λ. Also, push(s, x) = push(t, y) if and only if x = y and s = t.

As in some other branches of mathematics, it is customary to assume also that the stack states are only those whose existence can be proved from the axioms in a finite number of steps. In this case, it means that every stack is a finite sequence of values, that becomes the empty stack (Λ) after a finite number of pops. By themselves, the axioms above do not exclude the existence of infinite stacks (that can be popped forever, each time yielding a different state) or circular stacks (that return to the same state after a finite number of pops). In particular, they do not exclude states s such that pop(s) = s or push(s, x) = s for some x. However, since one cannot obtain such stack states from the initial stack state with the given operations, they are assumed "not to exist".

In the operational definition of an abstract stack, push(S, x) returns nothing and pop(S) yields the value as the result but not the new state of the stack. There is then the constraint that, for any value x and any abstract variable V, the sequence of operations { push(S, x); Vpop(S) } is equivalent to Vx. Since the assignment Vx, by definition, cannot change the state of S, this condition implies that Vpop(S) restores S to the state it had before the push(S, x). From this condition and from the properties of abstract variables, it follows, for example, that the sequence:

{ push(S, x); push(S, y); Upop(S); push(S, z); Vpop(S); Wpop(S) }

where x, y, and z are any values, and U, V, W are pairwise distinct variables, is equivalent to:

{ Uy; Vz; Wx }

Unlike the axiomatic semantics, the operational semantics can suffer from aliasing. Here it is implicitly assumed that operations on a stack instance do not modify the state of any other ADT instance, including other stacks; that is:

  • For any values x, y, and any distinct stacks S and T, the sequence { push(S, x); push(T, y) } is equivalent to { push(T, y); push(S, x) }.

Boom hierarchy

edit

A more involved example is the Boom hierarchy of the binary tree, list, bag and set abstract data types.[10] All these data types can be declared by three operations: null, which constructs the empty container, single, which constructs a container from a single element and append, which combines two containers of the same type. The complete specification for the four data types can then be given by successively adding the following rules over these operations:

null is the left and right neutral for a tree append(null,A) = A, append(A,null) = A.
lists add that append is associative append(append(A,B),C) = append(A,append(B,C)).
bags add commutativit append(B,A) = append(A,B).
finally, sets are also idempotent append(A,A) = A.

Access to the data can be specified by pattern-matching over the three operations, e.g. a member function for these containers by:

member(X,single(Y)) = eq(X,Y)
member(X,null) = false
member(X,append(A,B)) = or(member(X,A), member(X,B))

Care must be taken to ensure that the function is invariant under the relevant rules for the data type. Within each of the equivalence classes implied by the chosen subset of equations, it has to yield the same result for all of its members.

Common ADTs

edit

Some common ADTs, which have proved useful in a great variety of applications, are

Each of these ADTs may be defined in many ways and variants, not necessarily equivalent. For example, an abstract stack may or may not have a count operation that tells how many items have been pushed and not yet popped. This choice makes a difference not only for its clients but also for the implementation.

Abstract graphical data type

An extension of ADT for computer graphics was proposed in 1979:[11] an abstract graphical data type (AGDT). It was introduced by Nadia Magnenat Thalmann, and Daniel Thalmann. AGDTs provide the advantages of ADTs with facilities to build graphical objects in a structured way.

Implementation

edit

Abstract data types are theoretical entities, used (among other things) to simplify the description of abstract algorithms, to classify and evaluate data structures, and to formally describe the type systems of programming languages. However, an ADT may be implemented. This means each ADT instance or state is represented by some of the concrete data type or data structure, and for each abstract operation there is a corresponding procedure or function, and these implemented procedures satisfy the ADT's specifications and axioms up to some standard. In practice, the implementation is not perfect, and users must be aware of issues due to limitations of the representation and implemented procedures.

For example, integers may be specified as an ADT, defined by the distinguished values 0 and 1, the operations of addition, subtraction, multiplication, division (with care for division by zero), comparison, etc., behaving according to the familiar mathematical axioms in abstract algebra such as associativity, commutativity, and so on. However, in a computer, integers are most commonly represented as fixed-width 32-bit or 64-bit binary numbers. Users must be aware of issues with this representation, such as arithmetic overflow, where the ADT specifies a valid result but the representation is unable to accommodate this value. Nonetheless, for many purposes, the user can ignore these infidelities and simply use the implementation as if it were the abstract data type.

Usually, there are many ways to implement the same ADT, using several different concrete data structures. Thus, for example, an abstract stack can be implemented by a linked list or by an array. Different implementations of the ADT, having all the same properties and abilities, can be considered semantically equivalent and may be used somewhat interchangeably in code that uses the ADT. This provides a form of abstraction or encapsulation, and gives a great deal of flexibility when using ADT objects in different situations. For example, different implementations of the ADT may be more efficient in different situations; it is possible to use each in the situation where they are preferable, thus increasing overall efficiency. Code that uses an ADT implementation according to its interface will continue working even if the implementation of the ADT is changed.

In order to prevent clients from depending on the implementation, an ADT is often packaged as an opaque data type or handle of some sort,[12] in one or more modules, whose interface contains only the signature (number and types of the parameters and results) of the operations. The implementation of the module—namely, the bodies of the procedures and the concrete data structure used—can then be hidden from most clients of the module. This makes it possible to change the implementation without affecting the clients. If the implementation is exposed, it is known instead as a transparent data type.

Modern object-oriented languages, such as C++ and Java, support a form of abstract data types. When a class is used as a type, it is an abstract type that refers to a hidden representation. In this model, an ADT is typically implemented as a class, and each instance of the ADT is usually an object of that class. The module's interface typically declares the constructors as ordinary procedures, and most of the other ADT operations as methods of that class. Many modern programming languages, such as C++ and Java, come with standard libraries that implement numerous ADTs in this style. However, such an approach does not easily encapsulate multiple representational variants found in an ADT. It also can undermine the extensibility of object-oriented programs. In a pure object-oriented program that uses interfaces as types, types refer to behaviours, not representations.

The specification of some programming languages is intentionally vague about the representation of certain built-in data types, defining only the operations that can be done on them. Therefore, those types can be viewed as "built-in ADTs". Examples are the arrays in many scripting languages, such as Awk, Lua, and Perl, which can be regarded as an implementation of the abstract list.

In a formal specification language, ADTs may be defined axiomatically, and the language then allows manipulating values of these ADTs, thus providing a straightforward and immediate implementation. The OBJ family of programming languages for instance allows defining equations for specification and rewriting to run them. Such automatic implementations are usually not as efficient as dedicated implementations, however.

Example: implementation of the abstract stack

edit

As an example, here is an implementation of the abstract stack above in the C programming language.

Imperative-style interface

edit

An imperative-style interface might be:

typedef struct stack_Rep stack_Rep;       // type: stack instance representation (opaque record)
typedef stack_Rep* stack_T;               // type: handle to a stack instance (opaque pointer)
typedef void* stack_Item;                 // type: value stored in stack instance (arbitrary address)

stack_T stack_create(void);               // creates a new empty stack instance
void stack_push(stack_T s, stack_Item x); // adds an item at the top of the stack
stack_Item stack_pop(stack_T s);          // removes the top item from the stack and returns it
bool stack_empty(stack_T s);              // checks whether stack is empty

This interface could be used in the following manner:

#include <stack.h>          // includes the stack interface

stack_T s = stack_create(); // creates a new empty stack instance
int x = 17;
stack_push(s, &x);          // adds the address of x at the top of the stack
void* y = stack_pop(s);     // removes the address of x from the stack and returns it
if (stack_empty(s)) { }     // does something if stack is empty

This interface can be implemented in many ways. The implementation may be arbitrarily inefficient, since the formal definition of the ADT, above, does not specify how much space the stack may use, nor how long each operation should take. It also does not specify whether the stack state s continues to exist after a call xpop(s).

In practice the formal definition should specify that the space is proportional to the number of items pushed and not yet popped; and that every one of the operations above must finish in a constant amount of time, independently of that number. To comply with these additional specifications, the implementation could use a linked list, or an array (with dynamic resizing) together with two integers (an item count and the array size).

Functional-style interface

edit

Functional-style ADT definitions are more appropriate for functional programming languages, and vice versa. However, one can provide a functional-style interface even in an imperative language like C. For example:

typedef struct stack_Rep stack_Rep;          // type: stack state representation (opaque record)
typedef stack_Rep* stack_T;                  // type: handle to a stack state (opaque pointer)
typedef void* stack_Item;                    // type: value of a stack state (arbitrary address)

stack_T stack_empty(void);                   // returns the empty stack state
stack_T stack_push(stack_T s, stack_Item x); // adds an item at the top of the stack state and returns the resulting stack state
stack_T stack_pop(stack_T s);                // removes the top item from the stack state and returns the resulting stack state
stack_Item stack_top(stack_T s);             // returns the top item of the stack state

See also

edit

Notes

edit

Citations

edit
  1. ^ "Reading 10: Abstract Data Types". MIT.
  2. ^ Liskov & Zilles 1974.
  3. ^ Ehrig, H. (1985). Fundamentals of Algebraic Specification 1 - Equations and Initial Semantics. Springer-Verlag. ISBN 0-387-13718-1.
  4. ^ Wechler, Wolfgang (1992). Universal Algebra for Computer Scientists. Springer-Verlag. ISBN 0-387-54280-9.
  5. ^ Rudolf Lidl (2004). Abstract Algebra. Springer. ISBN 978-81-8128-149-4., Chapter 7, section 40.
  6. ^ Dale & Walker 1996, p. 3.
  7. ^ Dale & Walker 1996, p. 4.
  8. ^ Stevens, Al (March 1995). "Al Stevens Interviews Alex Stepanov". Dr. Dobb's Journal. Retrieved 31 January 2015.
  9. ^ Black, Paul E. (24 August 2005). "axiomatic semantics". Dictionary of Algorithms and Data Structures. Retrieved 25 November 2023.
  10. ^ Bunkenburg, Alexander (1994). "The Boom Hierarchy". Functional Programming, Glasgow 1993. Workshops in Computing. pp. 1–8. CiteSeerX 10.1.1.49.3252. doi:10.1007/978-1-4471-3236-3_1. ISBN 978-3-540-19879-6.
  11. ^ D. Thalmann, N. Magnenat Thalmann (1979). Design and Implementation of Abstract Graphical Data Types. IEEE. doi:10.1109/CMPSAC.1979.762551., Proc. 3rd International Computer Software and Applications Conference (COMPSAC'79), IEEE, Chicago, USA, pp.519-524
  12. ^ Robert Sedgewick (1998). Algorithms in C. Addison/Wesley. ISBN 978-0-201-31452-6., definition 4.4.

References

edit

Further reading

edit
edit
荆芥是什么菜 途明是什么档次的包 睡不着觉去医院挂什么科 脖子上有肿块挂什么科 奥特莱斯是什么店
给老师送花送什么花合适 心仪的人是什么意思 瞳孔是什么 脱发看什么科 野茶属于什么茶
吃什么食物能升白细胞 拔罐之后要注意什么 下焦湿热吃什么中成药 怎么知道自己五行缺什么 什么叫八字
肝功十二项包括什么 infp是什么意思 吃什么增肥最快 眼屎多用什么眼药水好 日柱灾煞是什么意思
人为什么没有尾巴hcv8jop8ns0r.cn 碳素厂是做什么的hcv8jop6ns5r.cn 甲减不能吃什么东西hcv8jop4ns6r.cn 淋巴瘤是什么症状weuuu.com 脖子上长疣是什么原因inbungee.com
蒲公英泡水喝有什么好处hcv8jop5ns0r.cn 绿色裤子配什么上衣hcv9jop0ns7r.cn 家奴是什么生肖hcv8jop9ns1r.cn 津津有味的意思是什么hcv8jop3ns7r.cn 凤梨跟菠萝有什么区别hcv8jop3ns2r.cn
张嘴睡觉是什么原因hcv9jop5ns4r.cn 月经和怀孕的症状有什么不同hcv8jop8ns2r.cn 白鹭吃什么hcv7jop9ns9r.cn 非虫念什么hcv9jop8ns2r.cn 什么文什么字hcv8jop1ns1r.cn
吹是什么意思hcv9jop5ns6r.cn 美联储加息意味着什么hcv9jop4ns3r.cn 喝什么降火hcv7jop5ns4r.cn prog是什么意思yanzhenzixun.com 什么是善hcv8jop5ns7r.cn
百度