100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

C++ implementation of abstract data types using an Array

Rating
-
Sold
-
Pages
6
Grade
A
Uploaded on
11-03-2026
Written in
2025/2026

This document gives examples of C++ codes for implementing abstract data types using an array.

Institution
Course

Content preview

Let's Implement the ADT (The "How")

Implementation 1: ArrayStack (Using an Array)



class ArrayStack : public Stack {

private:

int* array;

int capacity;

int topIndex; // Index of the top element



public:

ArrayStack(int size) {

capacity = size;

array = new int[capacity];

topIndex = -1; // Signifies an empty stack

}



~ArrayStack() {

delete[] array; // Clean up dynamic memory

}



void push(int value) override {

if (topIndex >= capacity - 1) {

cout << "Stack Overflow!" << endl;

return;

}

array[++topIndex] = value;

}

, int pop() override {

if (isEmpty()) {

cout << "Stack Underflow!" << endl;

return -1; // Error value

}

return array[topIndex--];

}



int peek() const override {

if (isEmpty()) {

cout << "Stack is Empty!" << endl;

return -1;

}

return array[topIndex];

}



bool isEmpty() const override {

return topIndex == -1;

}

};

Written for

Institution
Course

Document information

Uploaded on
March 11, 2026
Number of pages
6
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$5.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
williamndwiga003

Get to know the seller

Seller avatar
williamndwiga003 kirinyaga university
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 days
Number of followers
0
Documents
19
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions