Assignment 4 Wordpad
Assignment 4 Wordpad
#include <stdlib.h>
#include <time.h>
struct Node {
int data;
Node* next;
};
class ArrayStack {
private:
int* stack;
int top;
int capacity;
public:
ArrayStack(int size)
capacity = size;
top = -1;
}
void push(int item)
if (top == capacity - 1)
else
stack[++top] = item;
int pop()
if (isEmpty())
return -1;
else
return stack[top--];
}
bool isFull() {
bool isEmpty() {
int topElement()
if (isEmpty())
return -1;
else
return stack[top];
void display() {
if (isEmpty()) {
};
class LinkedListStack {
private:
Node* top;
public:
LinkedListStack()
top = NULL;
newNode->data = item;
newNode->next = NULL;
if (top == NULL)
top = newNode;
else
current = current->next;
current->next = newNode;
void pop()
if (isEmpty())
else
if (top->next == NULL)
{
delete top;
top = NULL;
else
current = current->next;
delete current->next;
current->next = NULL;
bool isFull() {
return false;
bool isEmpty() {
int topElement()
{
if (isEmpty())
return -1;
else
current = current->next;
return current->data;
void display() {
if (isEmpty()) {
} else {
current = current->next;
}
};
class ArrayQueue {
private:
int* queue;
int front;
int rear;
int capacity;
public:
ArrayQueue(int size) {
capacity = size;
bool isFull() {
bool isEmpty() {
if (isFull()) {
} else {
if (front == -1) {
front = 0;
queue[++rear] = item;
void qdelete() {
if (isEmpty()) {
} else {
if (front == rear) {
} else {
front++;
}
void display() {
if (isEmpty()) {
} else {
};
class LinkedListQueue {
private:
Node* front;
Node* rear;
public:
LinkedListQueue() {
bool isEmpty() {
}
void qinsert(int item) {
newNode->data = item;
newNode->next = NULL;
if (rear == NULL) {
} else {
rear->next = newNode;
rear = newNode;
void qdelete() {
if (isEmpty()) {
} else {
if (front == rear) {
} else {
front = front->next;
}
delete temp;
void displaylist() {
if (isEmpty()) {
} else {
current = current->next;
};
int main() {
int choice;
ArrayQueue arrayQueue(20);
LinkedListQueue linkedListQueue;
ArrayStack arrayStack(20);
LinkedListStack linkedListStack;
do {
MainMenu:
system("cls");
switch (choice) {
case 1: {
StackMenu:
system("cls");
switch (choice) {
case 1: {
do {
switch (subChoice) {
case 1: {
int item;
arrayStack.push(item);
arrayStack.display();
break;
case 2: {
arrayStack.pop();
arrayStack.display();
break;
case 3: {
if (arrayStack.isFull()) {
} else {
break;
case 4: {
if (arrayStack.isEmpty()) {
} else {
break;
case 5: {
if (top != -1) {
break;
}
case 6: {
goto StackMenu;
break;
default: {
break;
break;
case 2: {
LinkedListStack stack;
do {
LinkedListStackMenu:
switch (choice) {
case 1: {
int item;
stack.push(item);
stack.display();
break;
case 2: {
stack.pop();
stack.display();
break;
case 3: {
break;
case 4: {
if (stack.isEmpty()) {
} else {
cout << " not empty." << endl;
break;
case 5: {
if (top != -1) {
break;
case 6: {
goto StackMenu;
break;
default: {
break;
break;
case 3: {
goto MainMenu;
break;
default: {
break;
if (choice != 3) {
goto StackMenu;
break;
case 2: {
QueueMenu:
system("cls");
switch (choice) {
case 1: {
int subChoice;
do {
switch (subChoice) {
case 1: {
int item;
arrayQueue.qinsert(item);
arrayQueue.display();
break;
case 2: {
arrayQueue.qdelete();
arrayQueue.display();
break;
}
case 3: {
if (arrayQueue.isFull()) {
} else {
break;
case 4: {
if (arrayQueue.isEmpty()) {
} else {
break;
case 5: {
system("cls");
goto QueueMenu;
break;
default: {
break;
case 2: {
LinkedListQueue queue;
do {
LinkedListQueueMenu:
switch (choice) {
case 1: {
int item;
queue.displaylist();
break;
case 2: {
queue.qdelete();
queue.displaylist();
break;
case 3: {
break;
case 4: {
if (queue.isEmpty()) {
} else {
break;
case 5: {
goto QueueMenu;
break;
default: {
break;
break;
case 3: {
system("cls");
goto MainMenu;
break;
default: {
break;
if (choice != 3) {
goto QueueMenu;
break;
}
case 3: {
break;
default: {
break;
return 0;
------------------------------------------------------------------------------------------------------------------------------------------