One way to implement a stack is with a singly-linked list. The head pointer always points to the "top of the stack", and each element points to the next. Since you rarely, if ever, are interested in more than the top of the stack, this is one way, although not the most efficient way, to implement a dynamic stack.
Since a stack is an abstraction, the best way to do this is to use a C++ abstract class or JAVA interface, as that would allow you to fine tune the implementation without having to think about the utilization. Since since the category did not specify C++ or JAVA, however, that ends that discussion.
yes pagal
LIFO
hardware stack - a stack implemented in and entirely managed by hardware, this stack will have dedicated memory and registers in the physical hardware of the system.software stack - a stack implemented with and entirely managed by software, this stack will use a small piece of main RAM and variables declared in the program software (making it much easier to modify if necessary than a hardware stack).
Stacks are often implemented using the same node structure as a linked list.
The top of a stack implemented as a linked list is the head of the list. All insertions and extractions occur at the head thus a forward list (singly-linked list) is sufficient to implement a stack.
yes pagal
The damage from using the stack stopped when the company implemented new safety measures.
LIFO
hardware stack - a stack implemented in and entirely managed by hardware, this stack will have dedicated memory and registers in the physical hardware of the system.software stack - a stack implemented with and entirely managed by software, this stack will use a small piece of main RAM and variables declared in the program software (making it much easier to modify if necessary than a hardware stack).
Stacks are often implemented using the same node structure as a linked list.
The top of a stack implemented as a linked list is the head of the list. All insertions and extractions occur at the head thus a forward list (singly-linked list) is sufficient to implement a stack.
A Linked-List is basically a series of Nodes. Each Node contains two things: The contents, and the pointer to the next Node in the Linked-List. So you can traverse the Linked-List by following the "next" pointers in each Node, a bit like following road directions from city to city. A stack is an abstract data type where you have two operations: "push" and "pop". Pushing means to put an item in the stack, Popping means to get the first element of the stack. When you push an item onto a stack, you put the item at the top: so its like cutting in line to the very front. The last one in is now first, and thus, the first one out. Another helpful image is a "stack" of trays at a cafeteria -- you can only get the tray from the top of the stack, or put a tray on top of the stack. The very first tray in the stack is actually the one at the very bottom, and thus, the last one to be used. "First in, Last Out." A stack deals with what comes first/last, while a Linked-List describes how data is stored. A stack needs to store data, so a stack can be implemented as a Linked-List.
http://www.osix.net/modules/article/?id=275muzzy writes "Here's some code for you kids. It demonstrates the concept of stack, implemented with a linked list mechanism to support virtually infinitely large stack sizes. Happy reading."/* Simple Dynamically Allocating Stack Implementation in C** Copyright (C) 2002 Muzzy of Worst Coders*/
A stack can be implemented as an array or a list. If an array, simply push the new element onto the end of the array. If a list, point the new node at the head node then make the new node the new head of the list.
A stack is generally First In, Last Out, and a queue is First In First Out.Item can be added or removed only at one end in stack and in a queue insertion at the rear and deletion from the front.The basic operation of stack are 'push' and 'pop', on other hand of queue are 'enque' and 'dequeue'.
Traditional implementations of stacks, particularly those implemented in hardware, are generally physical data structures. That is, the data structure dictates how elements are arranged in memory.Modern software implementations take a more abstract approach however. Characteristic for a stack is not the physical arrangement of items in memory, but the set of characteristic operations and their behavior: a simple stack can execute push operations to add an item and pop operations to remove the most recently added item. More advanced stacks support additional stack operations to manipulate implicitly addressed stack elements, for example though common operations such as dup, swap, drop.Nothing in the behavior of these stack operations dictate that the stack shall be implemented as a physical data structure; in fact many modern runtime kits use higher order data structures such as linked lists to implement stacks and other basic data structures. Such a choice would be made to support an infinite size stack, for example, and in order to base the runtime kit on the smallest number of fundamental tools in order to promote robustness.
S: Stack while(more tokens) { x<-next token; if(x is an operand) print x else { while(precedence(x) <= precedence(top(s)) print(pop(s)) push(s,x) } } while(!empty(s)) print(pop(s)); Written by: Fabianski Benjamin