write program to convert FIFO into LIFO
Sigiloso
Lets assume we have a FIFO implemented as a Link List which has Head and Tail pointers associated with it. Nodes are added at the Tail and removed from the Head. To convert it to function like LIFO (Stack) all we have to change is the Get(FIFO) function to be equivalent to Pop(FIFO) into something like this: nodeStruct *Get(FIFO) { nodeStruct *nodePointer = Tail; //point to Top node Tail = Tail->Next; //relink Tail to point to 2nd-Top node return(nodePointer); } The Add(FIFO) will remain the same, and will be equivalent to Push(FIFO) and will be: void Add(FIFO, nodeStruct *nodePointer) { nodePointer->Next = Tail; //link New node to point to Top Node Tail = nodePointer; //point Tail pointer to New node } So to convert FIFO to a STACK, both Add() and Get() operations must be performed using FIFO's Tail pointer.