answersLogoWhite

0


Best Answer

A multiple stack program is a program with more than one stack. We are talking about program defined stacks, not the implicit stack that runs behind the scenes. One algorithm would be to create a linked list. The push operation, given the address of the pointer to the head of the stack, would allocate and insert an element in front of the head. Pop would retrieve the head and deallocate it. An incomplete example, using integers as the elements... (For readability, ... indicates tabs.) typedef struct stack_element_s {

... struct stack_element_s *next;

... int element;

} stack_element; int push (stack_element **stack_head, int *value) {

... stack_element *temp;

... stack_element *new_element;

... new_element = malloc (sizeof (stack_element));

... if (new_element == null) return 0; /* allocation failure !!! -- FATAL */

... temp = *stack_head;

... new_element->next = temp;

... new_element->element = *value;

... **stack_head = new_element;

... return 1;

} int pop (stack_element **stack_head, int *value) {

... stack_element *temp;

... temp = *stack_head;

... if (temp == null) return 0; /* stack empty */

... *value = temp->element;

... **stack_head = temp->next;

... free temp;

... return 1;

} stack_element *stack1 = null;

stack_element *stack2 = null; /* showing stack1, stack2 is similar. you can have as many stacks as you want */

int value;

if (!push (&stack1, &value)) exception_handler(); /* exception handler */

if (!pop (&stack1, &value)) stack_empty(); /* stack empty */

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Define a multiple stack. write algorithm for its implementation?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Design an algorithm to show the different operations on a stack?

Design an algorithm to show the different operations on a stack?


Define list of operation on stack?

There are 4 main widely used stack operations.Operations:* POP - increase stack pointer and return top element * PUSH - putting element into stack's top * TOP - returns data of top element on stack * LENGTH/SIZE - returns number of elements inside stack For more detailed implementation details, please check web links.


Is cursor implementation possible in queue or stack?

yes,cursor implementation possible in priority queue.


Write an algorithm to remove an item from the top of the stack?

It is not possible to write a code to POP from the stack when there is no your stack implementation information.Because of that I am going to talk more about Stack in computer architecture and there will be additional link to specific examples(-e).In x86 architecture there is three registers (BP, SP and SS) which are connected with stack and only SP and SS is needed.SS - Stack Segment (base register);SP - Stack Pointer (offset);This is how the POP instruction works:# operand = [SS:SP] (top of the stack) # SP = SP + 2; (change SP to point to new top element)


An algorithm to Reversing the order of elements on stack S using 1 additional stacks?

// stack to contain content Stack sourceStack = new Stack(); // ... fill sourceStack with content // stack to contain reversed content Stack targetStack = new Stack(); while (!sourceStack.empty()) { targetStack.push(sourceStack.pop()); } // targetStack contains the reversed content of sourceStack

Related questions

Design an algorithm to show the different operations on a stack?

Design an algorithm to show the different operations on a stack?


Define list of operation on stack?

There are 4 main widely used stack operations.Operations:* POP - increase stack pointer and return top element * PUSH - putting element into stack's top * TOP - returns data of top element on stack * LENGTH/SIZE - returns number of elements inside stack For more detailed implementation details, please check web links.


Is cursor implementation possible in queue or stack?

yes,cursor implementation possible in priority queue.


What is the importance of stack algorithm in your program?

Stack implementations allow us to easily implement backtracking algorithms.


Write an algorithm to remove an item from the top of the stack?

It is not possible to write a code to POP from the stack when there is no your stack implementation information.Because of that I am going to talk more about Stack in computer architecture and there will be additional link to specific examples(-e).In x86 architecture there is three registers (BP, SP and SS) which are connected with stack and only SP and SS is needed.SS - Stack Segment (base register);SP - Stack Pointer (offset);This is how the POP instruction works:# operand = [SS:SP] (top of the stack) # SP = SP + 2; (change SP to point to new top element)


C program to implement tower of hanoi using array implementation of stack abstract datatype?

stack abstract datatype


What are Disadvantage of stack?

A stack is a LIFO (last-in, first-out) data structure such that only the top-most element is accessible and all new elements are pushed onto the top (analogous to a stack of plates). Stacks are advantageous when implementing a back-tracking algorithm but are ultimately useless for anything else. However, this is not a disadvantage. If you're not implementing a back-tracking algorithm then the problem is not the stack itself it is the fact that you are using the wrong type of container for your algorithm.


An algorithm to Reversing the order of elements on stack S using 1 additional stacks?

// stack to contain content Stack sourceStack = new Stack(); // ... fill sourceStack with content // stack to contain reversed content Stack targetStack = new Stack(); while (!sourceStack.empty()) { targetStack.push(sourceStack.pop()); } // targetStack contains the reversed content of sourceStack


What time required to insert element in stack with linked implementation?

O(1)


Does x-booster unlimited stack if multiple bought in dragonfable?

The ability of it does not stack.


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.


What is 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.