answersLogoWhite

0


Best Answer

A stack is a last-in, first-out data structure (LIFO). A linked list gives you constant time access to the head of the list, thus all insertions (pushes) and extractions (pops) must be done at the head of the list to implement a stack:

Algorithm: push

Input: a linked list Lst and a value Val

Output: none

Nod = new node (Val) // instantiate a new node with given value

if Lst->count > 0 then Nod->next := Lst->head // point the new node at the head

Lst->head := Nod // make the new node the head

Lst->count := Lst->count + 1 // increment the count

Algorithm: pop

Input: a linked list, Lst Output: none

if Lst->count = 0 then return // can't pop from an empty list!

Old := Lst->head // store the current head

Lst->head := Lst->head->next // set the new head (may be null)

delete Old // delete the old head

Lst->count := Lst->count - 1 // decrement the count

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are algorithm for linked list implementation of stack?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the front of the stack in a stacked 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.


What is pseudo code algorithm for create a linked list with a header and insert a four numbers to the list?

pseudo code algorithm to create a linked list


Write an algorithm for the implementation of a circular doubly linked list?

Create a new node, making sure it is not allocated locally in the function and thus will not be destroyed when the function execution finishesFill in dataUse the "last node" pointer in the list and copy the "next" pointer location (pointing to the first node) into the new nodes "next" pointerSet the "last node" "next" pointer to point to the new nodeChange the list's "last node" pointer to point to the new nodeFor an example of implementation see: How_you_insert_a_newnode_in_singly_circular_link_list


Why is the constructor of the Stack Linked List class empty?

The default constructor of a stack is empty because the default value of any container, including a linked list, is an empty container which requires no arguments (all members default to zero).


What is the difference between linked list and Ordinary list?

A list is an abstract data structure, usually defined as an ordered collection of data. A linked list refers to a specific implementation of a list in which each element in the list is connected (linked) to the next element.

Related questions

What is the front of the stack in a stacked 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.


What is pseudo code algorithm for create a linked list with a header and insert a four numbers to the list?

pseudo code algorithm to create a linked list


Write an algorithm for the implementation of a circular doubly linked list?

Create a new node, making sure it is not allocated locally in the function and thus will not be destroyed when the function execution finishesFill in dataUse the "last node" pointer in the list and copy the "next" pointer location (pointing to the first node) into the new nodes "next" pointerSet the "last node" "next" pointer to point to the new nodeChange the list's "last node" pointer to point to the new nodeFor an example of implementation see: How_you_insert_a_newnode_in_singly_circular_link_list


Write a algorithm for doubly linked list in c?

sorry


Where linked list using?

linked list are used for creation of stack,queues to use memory in optimum manner linked list are used as they are dynamic in nature


Is it possible to implement stack and queues using linkes list?

Yes it is possible to implement stack and queue using linked list


Why is the constructor of the Stack Linked List class empty?

The default constructor of a stack is empty because the default value of any container, including a linked list, is an empty container which requires no arguments (all members default to zero).


What is the difference between linked list and Ordinary list?

A list is an abstract data structure, usually defined as an ordered collection of data. A linked list refers to a specific implementation of a list in which each element in the list is connected (linked) to the next element.


How do you copy all the elements from a given stack implemented in a linked list to a new one and returns the pointer to the new stack?

LIFO


What are the the two ways in representing the stack?

one-dimensional array, and doubly-linked list.


Stack example in c using push and pop?

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*/


What is a stock sorting algorithm?

Stock sorting algorithm is a algorithm which is used to sort any kind of stock i.e. any data type containing the primitive values like array ,link list ,stack etc.