SQ_implementation - Implementation of stack using an array...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Implementation of stack using an array We have seen in the lecture class how a stack can be implemented with push and pop functions to handle integers. In this section we shall show how to handle a situation when we have to deal both with integers and character information. Let us consider a factory where goods of varying quality are being produced in batches. We assume that all goods produced in a particular batch have the same quality. As the items are being produced, we want to store the information regarding the number of items produced and the quality of that batch ( ‘H’ for high quality, ‘G’ for good quality, ‘A’ for average quality etc.) on a stack using PUSH function. To deliver the items to a client, we want to use the POP function. The POP function is supposed to remove the items from the stack. We are also interested to find out if the stack is full or empty at any point in time using the functions ISFULL and ISEMPTY. We start by declaring the following structure which has two arrays, one storing the number of items being produced in every batch, while the other storing the quality of the goods in that batch. The variable top indicates the position of the last item in an array. The variable MAXSTACK defines the maximum size of the stack. #define MAXSTACK 20 //Here is the structure declaration: struct arraystack { int items[MAXSTACK]; char quality[MAXSTACK]; int top; }; Calling the stack functions from the main program int main( ) { // declare other variables…. // Declare the name of the stack structure as
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/12/2011.

Page1 / 6

SQ_implementation - Implementation of stack using an array...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online