CS2143-2144 Data Structures Quiz 2: Line-by-Line Explanation of stack Class, Exercises of Data Structures and Algorithms

The solution for quiz #2 of the cs2143-2144 data structures course, focusing on the line-by-line explanation of the stack class definition. It highlights potential issues and offers corrections.

Typology: Exercises

2011/2012

Uploaded on 07/11/2012

dharanidhar
dharanidhar 🇮🇳

4.2

(6)

58 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS2143-2144 Data Structures Spring 2012
Quiz # 2 (21 February 2012)
Time 10 Minutes
Max. Marks 10
Name: Reg. No: ___
Carefully see the following class definition. Explain line by line what is being done in the
code. Highlight if there is any problem in the definition / implementation and correct it.
class stack
{
protected:
int *ptr;
unsigned int size ;
unsigned int top;
public:
stack(unsigned S) {
ptr= new int[S];
top=0;
size=S;
}
int push(int value)
{
if (top>=s)
{
cout<<"FALSE";
return 0;
}
else{
ptr[top]=value;
top++;
}
}
int pop()
{
if (top==0)
{
cout<<"CANT GET THE VALUES";
return 0;
}
else
{
int C;
val=ptr[top];
--top;
return C;
}
} };
Docsity.com

Partial preview of the text

Download CS2143-2144 Data Structures Quiz 2: Line-by-Line Explanation of stack Class and more Exercises Data Structures and Algorithms in PDF only on Docsity!

CS2143-2144 Data Structures Spring 2012

Quiz # 2 (21 February 2012)

Time 10 Minutes

Max. Marks 10

Name: Reg. No: ___

Carefully see the following class definition. Explain line by line what is being done in the

code. Highlight if there is any problem in the definition / implementation and correct it.

class stack { protected: int *ptr; unsigned int size ; unsigned int top; public: stack(unsigned S) { ptr= new int[S]; top=0; size=S; } int push(int value) { if (top>=s) { cout<<"FALSE"; return 0; } else{ ptr[top]=value; top++; } } int pop() { if (top==0) { cout<<"CANT GET THE VALUES"; return 0; } else { int C; val=ptr[top]; --top; return C; } } };

Docsity.com