灵芝不能和什么一起吃| 伊人是什么意思| 什么地流着| 命悬一线的意思是什么| 白细胞低吃什么药可以增加白细胞| 海马是什么动物| 羊水污染是什么原因造成的| 牙齿疼是什么原因引起的| 天天都需要你爱是什么歌| 肢体麻木是什么原因| tpo是什么| 福生无量天尊什么意思| 什么的同学| 小猫吃什么东西| 锻炼pc肌有什么好处| 错构瘤是什么病| 血液发黑是什么原因| 什么是凌汛| 羡慕的意思是什么| 梦见房屋倒塌是什么征兆| 同型半胱氨酸是什么意思| 人乳头瘤病毒是什么意思| 小仙女什么意思| 鱼死了有什么预兆| 身上痒但是什么都没有| scr医学上是什么意思| 人流前需要检查什么项目| 陈皮泡水喝有什么作用| 农历五月的别称是什么| 内伤湿滞什么意思| 避孕套什么牌子好用又安全| 什么是直系亲属| 薄荷绿是什么颜色| 梦见死了人是什么意思| 住院需要带什么生活用品| 什么的劝告| 梦见手机丢了又找到了是什么意思| 什么知什么明| 消化不良反酸吃什么药| bpc是什么意思| 考拉吃什么食物| 称中药的小秤叫什么| 烤箱可以烤些什么东西| 肥达氏反应检查什么病| 空调外机不出水是什么原因| 晚上尿次数多什么原因| 荣辱与共是什么意思| 糯叽叽什么意思| 回肠荡气什么意思| 布谷鸟叫有什么征兆| 大腿麻木是什么原因| 亥时右眼跳是什么预兆| 华为最新款手机是什么型号| 莲子心和什么搭配泡水喝最好| 吃醪糟有什么好处| 打破伤风不能吃什么| 1月25号什么星座| 什么水果对肝脏好| 宝宝睡眠不好是什么原因| 吃山楂有什么好处| 麸皮是什么东西| 心机血缺血吃什么药最好| 花生对胃有什么好处| 什么是宫寒| 拿什么让你幸福| 双卵巢是什么意思| 梦到镯子碎了什么预兆| 杞人忧天告诉我们什么道理| 孩子流黄鼻涕吃什么药效果好| 上火便秘吃什么药| 想留不能留才最寂寞是什么歌| 博物馆里面有什么| 舍什么救什么| 数字化摄影dr是检查什么| 农历五月的别称是什么| 天蝎座男生喜欢什么样的女生| 正品行货是什么意思| 脾胃虚寒吃什么| 心肌缺血是什么原因引起的| cpr是什么| 苦瓜有什么作用| 醪糟是什么| 摩羯座女生和什么星座男生最配| 无脑是什么意思| 皮肤病吃什么药最好| 失落是什么意思| 全脂乳粉是什么| 家里进鸟了是什么预兆| 梦见狗咬别人是什么意思| 细菌性结膜炎用什么眼药水| 主管护师是什么职称| 什么情况下要做宫腔镜| qt什么意思| iris是什么意思啊| 墨鱼和鱿鱼有什么区别| 1978年属马五行缺什么| hsv病毒是什么意思| 甲状腺球蛋白抗体高是什么意思| 梦见两个小男孩是什么意思| 驴打滚是什么意思| 鱼周念什么| r一谷氨酰转移酶高说明什么| 淮山和山药有什么区别| 纤维硬结灶是什么意思| 吃什么对大脑记忆力好| 房间隔缺损是什么意思| 细菌感染吃什么药好| edsheeran为什么叫黄老板| 什么叫萎缩性胃炎| 创字五行属什么| 神经衰弱是什么意思| 母亲节可以做什么礼物| 什么是假性抑郁症| 教育的本质是什么| 老人脚肿是什么原因引起的| 心脏长什么样| 眼睛总是流泪是什么原因| 樱桃跟车厘子有什么区别| 宝宝大便有泡沫是什么原因| 傲娇是什么意思| 商纣王叫什么名字| 水煎服是什么意思| 过敏性紫癜什么症状| 长鸡眼是什么原因| 消化腺包括什么| 黄芪什么味道| 嘴唇红肿是什么原因| 身痒是什么原因引起的| 舌头发麻看什么科| 三岁打什么疫苗| 喉咙不舒服看什么科| 驴肉不能和什么一起吃| 感冒可以吃什么水果| 感康是什么| 嗓子疼咳嗽挂什么科| 什么是蚕豆病| 阿莫西林主要治疗什么| 什么鱼最好吃| 好久不见是什么意思| 什么解酒最快| 16年属什么| 谷丙转氨酶高是什么原因| 梁子是什么意思| 银杏树叶子像什么| 糖尿病2型是什么意思| 自字五行属什么| dcr是什么| dr是什么检查| 多梦是什么原因造成的| 宫颈醋酸白色上皮是什么病变| 什么是有限公司| 检查膝盖挂什么科| 93岁属什么生肖| 肌张力高吃什么药| 情绪高涨是什么意思| 十点多是什么时辰| 六味地黄丸是治什么病| 海藻面膜有什么作用| 肝气郁结喝什么茶| 孕期血糖高可以吃什么水果| 查幽门螺旋杆菌挂什么科| 梦见被狼追是什么意思| ige是什么| 白炽灯属于什么光源| 胬肉是什么意思| 本色出演是什么意思| 宫刑是什么意思| 朱元璋长什么样| 羊驼为什么吐口水| 肚子上面疼是什么原因| 达泊西汀是什么药| 什么克风| 羊水穿刺检查什么| 做梦买房子是什么预兆| 公鸡蛋是什么| 抹茶绿配什么颜色好看| 不忘初心方得始终是什么意思| dunk是什么意思| 护理员是干什么的| 前列腺特异性抗原是什么意思| 初级会计什么时候拿证| 作灶是什么意思| 繁星是什么意思| bc是什么| 起居是什么意思| 尿潜血是什么病| 动脉钙化是什么意思| 什么病会吐血| 牙龈经常发炎是什么原因| 首饰是什么意思| 脾切除后有什么影响| 见招拆招下一句是什么| 人乳头瘤病毒18型阳性是什么意思| 男生下面疼是什么原因| 左室高电压是什么意思| 膘是什么意思| 沼泽地是什么意思| hpv11阳性是什么意思| 奇货可居是什么意思| 间隙是什么意思| 女人男相有什么说法| 张信哲为什么不结婚| 梦见恐龙是什么预兆| 治疗勃起困难有什么药| 玉五行属性是什么| 普洱在云南什么位置| 石女是什么意思啊| 手术后吃什么伤口愈合快| 结婚下雨有什么说法| 痛风不能吃什么食物表| 气血不足什么症状| 什么的勇气| 鸡蛋过敏什么症状| 症瘕病是什么病| 什么的猴子| 女人什么时候绝经正常| 春风得意是什么生肖| 真菌阴性是什么意思| 老是嗝气是什么原因| 三十八岁属什么生肖| 邪是什么意思| 歧视什么意思| 发癫是什么意思| 刀枪不入是什么生肖| 女性尿频尿急吃什么药| 黔驴技穷是什么意思| 单亲妈妈是什么意思| 产前筛查是检查什么| 据说是什么意思| 捣碎东西的器皿叫什么| 大姨妈一个月来两次是什么原因| 性功能下降吃什么药好| 女性尿道出血是什么原因引起的| 鱼用什么游泳| 鸟屎掉身上有什么预兆| 神经衰弱吃什么药效果最好| 微腺瘤是什么| 金银花洗澡对婴儿有什么好处| 附件炎是什么引起的| notebook是什么意思| 口臭睡觉流口水什么原因| 水泻拉肚子是什么原因| 海豹吃什么| 老放屁吃什么药| 党内的最高处分是什么| 麦粒肿吃什么药| 744是什么意思| 饕餮长什么样| 光年是什么单位| 病理科是干什么的| 尿酸520属于什么水平| 3.7号是什么星座| hbr是什么意思| 肺部纤维化是什么意思| 火棉胶婴儿是什么意思| 2016年是什么生肖| 阿胶补血口服液适合什么人喝| 7.1是什么星座| 遗精频繁是什么原因| 下身有异味用什么药| 吐黑水是什么原因| beside是什么意思| 苹果5s什么时候上市的| 低压高吃点什么药| 百度
百度 但是,他给年轻一代带来的还不仅仅是信心。

In computer science, a stack is an abstract data type that serves as a collection of elements with two main operations:

  • Push, which adds an element to the collection, and
  • Pop, which removes the most recently added element.
Similarly to a stack of plates, adding or removing is only practical at the top.
Simple representation of a stack runtime with push and pop operations.

Additionally, a peek operation can, without modifying the stack, return the value of the last element added. The name stack is an analogy to a set of physical items stacked one atop another, such as a stack of plates.

The order in which an element added to or removed from a stack is described as last in, first out, referred to by the acronym LIFO.[nb 1] As with a stack of physical objects, this structure makes it easy to take an item off the top of the stack, but accessing a datum deeper in the stack may require removing multiple other items first.[1]

Considered a sequential collection, a stack has one end which is the only position at which the push and pop operations may occur, the top of the stack, and is fixed at the other end, the bottom. A stack may be implemented as, for example, a singly linked list with a pointer to the top element.

A stack may be implemented to have a bounded capacity. If the stack is full and does not contain enough space to accept another element, the stack is in a state of stack overflow.

History

edit

Stacks entered the computer science literature in 1946, when Alan Turing used the terms "bury" and "unbury" as a means of calling and returning from subroutines.[2][3] Subroutines and a two-level stack had already been implemented in Konrad Zuse's Z4 in 1945.[4][5]

Klaus Samelson and Friedrich L. Bauer of Technical University Munich proposed the idea of a stack called Operationskeller ("operational cellar") in 1955[6][7] and filed a patent in 1957.[8][9][10][11] In March 1988, by which time Samelson was deceased, Bauer received the IEEE Computer Pioneer Award for the invention of the stack principle.[12][7] Similar concepts were independently developed by Charles Leonard Hamblin in the first half of 1954[13][7] and by Wilhelm K?mmerer [de] with his automatisches Ged?chtnis ("automatic memory") in 1958.[14][15][7]

Stacks are often described using the analogy of a spring-loaded stack of plates in a cafeteria.[16][1][17] Clean plates are placed on top of the stack, pushing down any plates already there. When the top plate is removed from the stack, the one below it is elevated to become the new top plate.

Non-essential operations

edit

In many implementations, a stack has more operations than the essential "push" and "pop" operations. An example of a non-essential operation is "top of stack", or "peek", which observes the top element without removing it from the stack.[18] Since this can be broken down into a "pop" followed by a "push" to return the same data to the stack, it is not considered an essential operation. If the stack is empty, an underflow condition will occur upon execution of either the "stack top" or "pop" operations. Additionally, many implementations include convenience operations that handle common tasks, such as checking if the stack is empty or returning its size.

Software stacks

edit

Implementation

edit

A stack can be easily implemented either through an array or a linked list, as it is merely a special case of a list.[19] In either case, what identifies the data structure as a stack is not the implementation but the interface: the user is only allowed to pop or push items onto the array or linked list, with few other helper operations. The following will demonstrate both implementations using pseudocode.

Array

edit

An array can be used to implement a (bounded) stack, as follows. The first element, usually at the zero offset, is the bottom, resulting in array[0] being the first element pushed onto the stack and the last element popped off. The program must keep track of the size (length) of the stack, using a variable top that records the number of items pushed so far, therefore pointing to the place in the array where the next element is to be inserted (assuming a zero-based index convention). Thus, the stack itself can be effectively implemented as a three-element structure:

structure stack:
    maxsize : integer
    top : integer
    items : array of item
procedure initialize(stk : stack, size : integer):
    stk.items ← new array of size items, initially empty
    stk.maxsize ← size
    stk.top ← 0

The push operation adds an element and increments the top index, after checking for overflow:

procedure push(stk : stack, x : item):
    if stk.top = stk.maxsize:
        report overflow error
    else:
        stk.items[stk.top] ← x
        stk.top ← stk.top + 1

Similarly, pop decrements the top index after checking for underflow, and returns the item that was previously the top one:

procedure pop(stk : stack):
    if stk.top = 0:
        report underflow error
    else:
        stk.top ← stk.top ? 1
        r ← stk.items[stk.top]
        return r

Using a dynamic array, it is possible to implement a stack that can grow or shrink as much as needed. The size of the stack is simply the size of the dynamic array, which is a very efficient implementation of a stack since adding items to or removing items from the end of a dynamic array requires amortized O(1) time.

Linked list

edit

Another option for implementing stacks is to use a singly linked list. A stack is then a pointer to the "head" of the list, with perhaps a counter to keep track of the size of the list:

structure frame:
    data : item
    next : frame or nil
structure stack:
    head : frame or nil
    size : integer
procedure initialize(stk : stack):
    stk.head ← nil
    stk.size ← 0

Pushing and popping items happens at the head of the list; overflow is not possible in this implementation (unless memory is exhausted):

procedure push(stk : stack, x : item):
    newhead ← new frame
    newhead.data ← x
    newhead.next ← stk.head
    stk.head ← newhead
    stk.size ← stk.size + 1
procedure pop(stk : stack):
    if stk.head = nil:
        report underflow error
    r ← stk.head.data
    stk.head ← stk.head.next
    stk.size ← stk.size - 1
    return r

Stacks and programming languages

edit

Some languages, such as Perl, LISP, JavaScript and Python, make the stack operations push and pop available on their standard list/array types. Some languages, notably those in the Forth family (including PostScript), are designed around language-defined stacks that are directly visible to and manipulated by the programmer.

The following is an example of manipulating a stack in Common Lisp (">" is the Lisp interpreter's prompt; lines not starting with ">" are the interpreter's responses to expressions):

> (setf stack (list 'a 'b 'c))  ;; set the variable "stack"
(A B C)
> (pop stack)  ;; get top (leftmost) element, should modify the stack
A
> stack        ;; check the value of stack
(B C)
> (push 'new stack)  ;; push a new top onto the stack
(NEW B C)

Several of the C++ Standard Library container types have push_back and pop_back operations with LIFO semantics; additionally, the stack template class adapts existing containers to provide a restricted API with only push/pop operations. PHP has an SplStack class. Java's library contains a Stack class that is a specialization of Vector. Following is an example program in Java language, using that class.

import java.util.Stack;

class StackDemo {
    public static void main(String[]args) {
        Stack<String> stack = new Stack<String>();
        stack.push("A");    // Insert "A" in the stack
        stack.push("B");    // Insert "B" in the stack
        stack.push("C");    // Insert "C" in the stack
        stack.push("D");    // Insert "D" in the stack
        System.out.println(stack.peek());    // Prints the top of the stack ("D")
        stack.pop();    // removing the top ("D")
        stack.pop();    // removing the next top ("C")
    }
}

Some processors, such as the PDP-11, VAX, and Motorola 68000 series have addressing modes useful for stack manipulation. The following trivial PDP-11 assembly source code pushes two numbers on a stack and adds them, leaving the result on the stack.

; R0 is assumed to point to a stack area
; -(R0) pre-decrements stack pointer allocating item on stack
; (R0)+ Post-increments stack pointer removing item on stack
;
       MOV    #12,-(R0)         ; Push 12 on stack
	   MOV    #34,-(R0)         ; push 34 on stack
	   ADD 	  (R0)+,(R0)        ; Pop 34 off stack and add to 12
                                ; leaving the result on the stack

Hardware stack

edit

A common use of stacks at the architecture level is as a means of allocating and accessing memory.

Basic architecture of a stack

edit

A typical stack is an area of computer memory with a fixed origin and a variable size. Initially the size of the stack is zero. A stack pointer (usually in the form of a processor register) points to the most recently referenced location on the stack; when the stack has a size of zero, the stack pointer points to the origin of the stack.

The two operations applicable to all stacks are:

  • A push operation: the address in the stack pointer is adjusted by the size of the data item and a data item is written at the location to which the stack pointer points.
  • A pop or pull operation: a data item at the current location to which the stack pointer points is read, and the stack pointer is moved by a distance corresponding to the size of that data item.

There are many variations on the basic principle of stack operations. Every stack has a fixed location in memory at which it begins. As data items are added to the stack, the stack pointer is displaced to indicate the current extent of the stack, which expands away from the origin.

Stack pointers may point to the origin of a stack or to a limited range of addresses above or below the origin (depending on the direction in which the stack grows); however, the stack pointer cannot cross the origin of the stack. In other words, if the origin of the stack is at address 1000 and the stack grows downwards (towards addresses 999, 998, and so on), the stack pointer must never be incremented beyond 1000 (to 1001 or beyond). If a pop operation on the stack causes the stack pointer to move past the origin of the stack, a stack underflow occurs. If a push operation causes the stack pointer to increment or decrement beyond the maximum extent of the stack, a stack overflow occurs.

Some environments that rely heavily on stacks may provide additional operations, for example:

  • Duplicate: the top item is popped and then pushed twice, such that two copies of the former top item now lie at the top.
  • Peek: the topmost item is inspected (or returned), but the stack pointer and stack size does not change (meaning the item remains on the stack). This can also be called the top operation.
  • Swap or exchange: the two topmost items on the stack exchange places.
  • Rotate (or Roll): the n topmost items are moved on the stack in a rotating fashion. For example, if n = 3, items 1, 2, and 3 on the stack are moved to positions 2, 3, and 1 on the stack, respectively. Many variants of this operation are possible, with the most common being called left rotate and right rotate.

Stacks are often visualized growing from the bottom up (like real-world stacks). They may also be visualized growing from left to right, where the top is on the far right, or even growing from top to bottom. The important feature is for the bottom of the stack to be in a fixed position. The illustration in this section is an example of a top-to-bottom growth visualization: the top (28) is the stack "bottom", since the stack "top" (9) is where items are pushed or popped from.

A right rotate will move the first element to the third position, the second to the first and the third to the second. Here are two equivalent visualizations of this process:

apple                         banana
banana    ===right rotate==>  cucumber
cucumber                      apple
cucumber                      apple
banana    ===left rotate==>   cucumber
apple                         banana

A stack is usually represented in computers by a block of memory cells, with the "bottom" at a fixed location, and the stack pointer holding the address of the current "top" cell in the stack. The "top" and "bottom" nomenclature is used irrespective of whether the stack actually grows towards higher memory addresses.

Pushing an item on to the stack adjusts the stack pointer by the size of the item (either decrementing or incrementing, depending on the direction in which the stack grows in memory), pointing it to the next cell, and copies the new top item to the stack area. Depending again on the exact implementation, at the end of a push operation, the stack pointer may point to the next unused location in the stack, or it may point to the topmost item in the stack. If the stack points to the current topmost item, the stack pointer will be updated before a new item is pushed onto the stack; if it points to the next available location in the stack, it will be updated after the new item is pushed onto the stack.

Popping the stack is simply the inverse of pushing. The topmost item in the stack is removed and the stack pointer is updated, in the opposite order of that used in the push operation.

Stack in main memory

edit

Many CISC-type CPU designs, including the x86, Z80 and 6502, have a dedicated register for use as the call stack stack pointer with dedicated call, return, push, and pop instructions that implicitly update the dedicated register, thus increasing code density. Some CISC processors, like the PDP-11 and the 68000, also have special addressing modes for implementation of stacks, typically with a semi-dedicated stack pointer as well (such as A7 in the 68000). In contrast, most RISC CPU designs do not have dedicated stack instructions and therefore most, if not all, registers may be used as stack pointers as needed.

Stack in registers or dedicated memory

edit
 
The programmable pocket calculator HP-42S from 1988 had, like nearly all of the company's calculators of that time, a 4-level-stack and could display two of four values of the stack registers X, Y, Z, and T at the same time due to its two-line display, here X and Y. In later models like the HP-48, the number of levels was increased to be only limited by memory size.

Some machines use a stack for arithmetic and logical operations; operands are pushed onto the stack, and arithmetic and logical operations act on the top one or more items on the stack, popping them off the stack and pushing the result onto the stack. Machines that function in this fashion are called stack machines.

A number of mainframes and minicomputers were stack machines, the most famous being the Burroughs large systems. Other examples include the CISC HP 3000 machines and the CISC machines from Tandem Computers.

The x87 floating point architecture is an example of a set of registers organised as a stack where direct access to individual registers (relative to the current top) is also possible.

Having the top-of-stack as an implicit argument allows for a small machine code footprint with a good usage of bus bandwidth and code caches, but it also prevents some types of optimizations possible on processors permitting random access to the register file for all (two or three) operands. A stack structure also makes superscalar implementations with register renaming (for speculative execution) somewhat more complex to implement, although it is still feasible, as exemplified by modern x87 implementations.

Sun SPARC, AMD Am29000, and Intel i960 are all examples of architectures that use register windows within a register-stack as another strategy to avoid the use of slow main memory for function arguments and return values.

There is also a number of small microprocessors that implement a stack directly in hardware, and some microcontrollers have a fixed-depth stack that is not directly accessible. Examples are the PIC microcontrollers, the Computer Cowboys MuP21, the Harris RTX line, and the Novix NC4016. At least one microcontroller family, the COP400, implements a stack either directly in hardware or in RAM via a stack pointer, depending on the device. Many stack-based microprocessors were used to implement the programming language Forth at the microcode level.

Applications of stacks

edit

Expression evaluation and syntax parsing

edit

Calculators that employ reverse Polish notation use a stack structure to hold values. Expressions can be represented in prefix, postfix or infix notations and conversion from one form to another may be accomplished using a stack. Many compilers use a stack to parse syntax before translation into low-level code. Most programming languages are context-free languages, allowing them to be parsed with stack-based machines.

Backtracking

edit

Another important application of stacks is backtracking. An illustration of this is the simple example of finding the correct path in a maze that contains a series of points, a starting point, several paths and a destination. If random paths must be chosen, then after following an incorrect path, there must be a method by which to return to the beginning of that path. This can be achieved through the use of stacks, as a last correct point can be pushed onto the stack, and popped from the stack in case of an incorrect path.

The prototypical example of a backtracking algorithm is depth-first search, which finds all vertices of a graph that can be reached from a specified starting vertex. Other applications of backtracking involve searching through spaces that represent potential solutions to an optimization problem. Branch and bound is a technique for performing such backtracking searches without exhaustively searching all of the potential solutions in such a space.

Compile-time memory management

edit
 
A typical call stack, storing local data and call information for multiple levels of procedure calls. This stack grows downward from its origin. The stack pointer points to the current topmost datum on the stack. A push operation decrements the pointer and copies the data to the stack; a pop operation copies data from the stack and then increments the pointer. Each procedure called in the program stores procedure return information (in yellow) and local data (in other colors) by pushing them onto the stack. This type of stack implementation is extremely common, but it is vulnerable to buffer overflow attacks (see the text).

A number of programming languages are stack-oriented, meaning they define most basic operations (adding two numbers, printing a character) as taking their arguments from the stack, and placing any return values back on the stack. For example, PostScript has a return stack and an operand stack, and also has a graphics state stack and a dictionary stack. Many virtual machines are also stack-oriented, including the p-code machine and the Java Virtual Machine.

Almost all calling conventions?—?the ways in which subroutines receive their parameters and return results?—?use a special stack (the "call stack") to hold information about procedure/function calling and nesting in order to switch to the context of the called function and restore to the caller function when the calling finishes. The functions follow a runtime protocol between caller and callee to save arguments and return value on the stack. Stacks are an important way of supporting nested or recursive function calls. This type of stack is used implicitly by the compiler to support CALL and RETURN statements (or their equivalents) and is not manipulated directly by the programmer.

Some programming languages use the stack to store data that is local to a procedure. Space for local data items is allocated from the stack when the procedure is entered, and is deallocated when the procedure exits. The C programming language is typically implemented in this way. Using the same stack for both data and procedure calls has important security implications (see below) of which a programmer must be aware in order to avoid introducing serious security bugs into a program.

Efficient algorithms

edit

Several algorithms use a stack (separate from the usual function call stack of most programming languages) as the principal data structure with which they organize their information. These include:

  • Graham scan, an algorithm for the convex hull of a two-dimensional system of points. A convex hull of a subset of the input is maintained in a stack, which is used to find and remove concavities in the boundary when a new point is added to the hull.[20]
  • Part of the SMAWK algorithm for finding the row minima of a monotone matrix uses stacks in a similar way to Graham scan.[21]
  • All nearest smaller values, the problem of finding, for each number in an array, the closest preceding number that is smaller than it. One algorithm for this problem uses a stack to maintain a collection of candidates for the nearest smaller value. For each position in the array, the stack is popped until a smaller value is found on its top, and then the value in the new position is pushed onto the stack.[22]
  • The nearest-neighbor chain algorithm, a method for agglomerative hierarchical clustering based on maintaining a stack of clusters, each of which is the nearest neighbor of its predecessor on the stack. When this method finds a pair of clusters that are mutual nearest neighbors, they are popped and merged.[23]

Security

edit

Some computing environments use stacks in ways that may make them vulnerable to security breaches and attacks. Programmers working in such environments must take special care to avoid such pitfalls in these implementations.

As an example, some programming languages use a common stack to store both data local to a called procedure and the linking information that allows the procedure to return to its caller. This means that the program moves data into and out of the same stack that contains critical return addresses for the procedure calls. If data is moved to the wrong location on the stack, or an oversized data item is moved to a stack location that is not large enough to contain it, return information for procedure calls may be corrupted, causing the program to fail.

Malicious parties may attempt a stack smashing attack that takes advantage of this type of implementation by providing oversized data input to a program that does not check the length of input. Such a program may copy the data in its entirety to a location on the stack, and in doing so, it may change the return addresses for procedures that have called it. An attacker can experiment to find a specific type of data that can be provided to such a program such that the return address of the current procedure is reset to point to an area within the stack itself (and within the data provided by the attacker), which in turn contains instructions that carry out unauthorized operations.

This type of attack is a variation on the buffer overflow attack and is an extremely frequent source of security breaches in software, mainly because some of the most popular compilers use a shared stack for both data and procedure calls, and do not verify the length of data items. Frequently, programmers do not write code to verify the size of data items, either, and when an oversized or undersized data item is copied to the stack, a security breach may occur.

See also

edit

Notes

edit
  1. ^ By contrast, a queue operates first in, first out, referred to by the acronym FIFO.

References

edit
  1. ^ a b Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2009) [1990]. Introduction to Algorithms (3rd ed.). MIT Press and McGraw-Hill. pp. 232–233. ISBN 0-262-03384-4.
  2. ^ Turing, Alan Mathison (2025-08-05) [1945]. Proposals for Development in the Mathematics Division of an Automatic Computing Engine (ACE). (NB. Presented on 2025-08-05 before the Executive Committee of the National Physical Laboratory (Great Britain).)
  3. ^ Carpenter, Brian Edward; Doran, Robert William (2025-08-05) [October 1975]. "The other Turing machine". The Computer Journal. 20 (3): 269–279. doi:10.1093/comjnl/20.3.269. (11 pages)
  4. ^ Blaauw, Gerrit Anne; Brooks, Jr., Frederick Phillips (1997). Computer architecture: Concepts and evolution. Boston, Massachusetts, USA: Addison-Wesley Longman Publishing Co., Inc.
  5. ^ LaForest, Charles Eric (April 2007). "2.1 Lukasiewicz and the First Generation: 2.1.2 Germany: Konrad Zuse (1910–1995); 2.2 The First Generation of Stack Computers: 2.2.1 Zuse Z4". Second-Generation Stack Computer Architecture (PDF) (thesis). Waterloo, Canada: University of Waterloo. pp. 8, 11. Archived (PDF) from the original on 2025-08-05. Retrieved 2025-08-05. (178 pages)
  6. ^ Samelson, Klaus (1957) [1955]. Written at Internationales Kolloquium über Probleme der Rechentechnik, Dresden, Germany. Probleme der Programmierungstechnik (in German). Berlin, Germany: VEB Deutscher Verlag der Wissenschaften. pp. 61–68. (NB. This paper was first presented in 1955. It describes a number stack (Zahlenkeller), but names it linear auxiliary memory (linearer Hilfsspeicher).)
  7. ^ a b c d Fothe, Michael; Wilke, Thomas, eds. (2015) [2025-08-05]. Written at Jena, Germany. Keller, Stack und automatisches Ged?chtnis – eine Struktur mit Potenzial [Cellar, stack and automatic memory - a structure with potential] (PDF) (Tagungsband zum Kolloquium 14. November 2014 in Jena). GI Series: Lecture Notes in Informatics (LNI) – Thematics (in German). Vol. T-7. Bonn, Germany: Gesellschaft für Informatik (GI) / K?llen Druck + Verlag GmbH. ISBN 978-3-88579-426-4. ISSN 1614-3213. Archived (PDF) from the original on 2025-08-05. Retrieved 2025-08-05. [1] (77 pages)
  8. ^ Bauer, Friedrich Ludwig; Samelson, Klaus (2025-08-05). "Verfahren zur automatischen Verarbeitung von kodierten Daten und Rechenmaschine zur Ausübung des Verfahrens" (in German). Munich, Germany: Deutsches Patentamt. DE-PS 1094019. Retrieved 2025-08-05.
  9. ^ Bauer, Friedrich Ludwig; Goos, Gerhard [in German] (1982). Informatik – Eine einführende übersicht (in German). Vol. Part 1 (3 ed.). Berlin: Springer-Verlag. p. 222. ISBN 3-540-11722-9. Die Bezeichnung 'Keller' hierfür wurde von Bauer und Samelson in einer deutschen Patentanmeldung vom 30. M?rz 1957 eingeführt.
  10. ^ Samelson, Klaus; Bauer, Friedrich Ludwig (1959). "Sequentielle Formelübersetzung" [Sequential Formula Translation]. Elektronische Rechenanlagen (in German). 1 (4): 176–182.
  11. ^ Samelson, Klaus; Bauer, Friedrich Ludwig (1960). "Sequential Formula Translation". Communications of the ACM. 3 (2): 76–83. doi:10.1145/366959.366968. S2CID 16646147.
  12. ^ "IEEE-Computer-Pioneer-Preis – Bauer, Friedrich L." Technical University of Munich, Faculty of Computer Science. 2025-08-05. Archived from the original on 2025-08-05.
  13. ^ Hamblin, Charles Leonard (May 1957). An Addressless Coding Scheme based on Mathematical Notation (PDF) (typescript). N.S.W. University of Technology. pp. 121-1 – 121-12. Archived (PDF) from the original on 2025-08-05. Retrieved 2025-08-05. (12 pages)
  14. ^ K?mmerer, Wilhelm [in German] (2025-08-05). Ziffern-Rechenautomat mit Programmierung nach mathematischem Formelbild (Habilitation thesis) (in German). Jena, Germany: Mathematisch-naturwissenschaftliche Fakult?t, Friedrich-Schiller-Universit?t. urn:nbn:de:gbv:27-20130731-133019-7. PPN:756275237. Archived from the original on 2025-08-05. Retrieved 2025-08-05. [2] (2+69 pages)
  15. ^ K?mmerer, Wilhelm [in German] (1960). Ziffernrechenautomaten. Elektronisches Rechnen und Regeln (in German). Vol. 1. Berlin, Germany: Akademie-Verlag.
  16. ^ Ball, John A. (1978). Algorithms for RPN calculators (1 ed.). Cambridge, Massachusetts, USA: Wiley-Interscience, John Wiley & Sons, Inc. ISBN 978-0-471-03070-6. LCCN 77-14977.
  17. ^ Godse, Atul P.; Godse, Deepali A. (2025-08-05). Computer Architecture. Technical Publications. pp. 1–56. ISBN 978-8-18431534-9. Retrieved 2025-08-05.
  18. ^ Horowitz, Ellis (1984). Fundamentals of Data Structures in Pascal. Computer Science Press. p. 67.
  19. ^ Pandey, Shreesham (2020). "Data Structures in a Nutshell". Dev Genius. 2020. SSRN 4145204.
  20. ^ Graham, Ronald "Ron" Lewis (1972). An Efficient Algorithm for Determining the Convex Hull of a Finite Planar Set (PDF). Information Processing Letters 1. Vol. 1. pp. 132–133. Archived (PDF) from the original on 2025-08-05.
  21. ^ Aggarwal, Alok; Klawe, Maria M.; Moran, Shlomo; Shor, Peter; Wilber, Robert (1987). "Geometric applications of a matrix-searching algorithm". Algorithmica. 2 (1–4): 195–208. doi:10.1007/BF01840359. MR 0895444. S2CID 7932878..
  22. ^ Berkman, Omer; Schieber, Baruch; Vishkin, Uzi (1993). "Optimal doubly logarithmic parallel algorithms based on finding all nearest smaller values". Journal of Algorithms. 14 (3): 344–370. CiteSeerX 10.1.1.55.5669. doi:10.1006/jagm.1993.1018..
  23. ^ Murtagh, Fionn (1983). "A survey of recent advances in hierarchical clustering algorithms" (PDF). The Computer Journal. 26 (4): 354–359. doi:10.1093/comjnl/26.4.354..

Further reading

edit
edit
右束支传导阻滞是什么病 吉利丁片是什么东西 小腿肚抽筋是什么原因 困是什么意思 肚脐眼疼吃什么药
双氢克尿噻又叫什么 气加山念什么 韩国买什么东西划算 发动机抖动是什么原因 胸口闷堵是什么原因
中之人什么意思 贤上腺瘤是什么意思 正团级是什么军衔 孕妇血压低吃什么能补上来 什么叫换手率
亚甲炎是什么原因引起的 生辰八字查五行缺什么 2002年五行属什么命 隆鼻后吃什么消肿快 打强心针意味着什么
低烧吃什么药好hcv9jop8ns2r.cn snidel是什么牌子hcv9jop0ns3r.cn 什么是树洞tiangongnft.com 14数字代表什么意思hcv8jop4ns9r.cn 痘痘破了涂什么药膏hcv9jop3ns4r.cn
二月十号是什么星座hcv8jop9ns7r.cn 口腔医学专业学什么hcv9jop0ns7r.cn 鲨鱼是什么动物wmyky.com 五官端正是什么意思hcv8jop0ns9r.cn 慢性盆腔炎吃什么药效果好hcv8jop2ns0r.cn
做完雾化为什么要漱口wzqsfys.com 补牙是什么意思hcv7jop4ns5r.cn 十月二十是什么星座wmyky.com 脾胃不好吃什么水果好wmyky.com 阳痿早泄是什么意思hcv9jop3ns4r.cn
胪是什么意思hcv9jop6ns9r.cn 彩色多普勒超声常规检查是什么clwhiglsz.com 胃火重口臭吃什么药好hcv8jop2ns4r.cn 什么情况下需要做喉镜检查hcv9jop8ns0r.cn 毛滴虫病是什么病hcv8jop2ns8r.cn
百度