Beginner Computer Science Coding- Stacks -- 2

Ολοκληρωμένο Αναρτήθηκε Dec 12, 2014 Πληρώθηκε κατά την παράδοση
Ολοκληρωμένο Πληρώθηκε κατά την παράδοση

The stack is a commonly used data structure in computer science. It is an arrangement of data where the last item to be added is the first one to be removed. Think of it as a stack of papers. As you stack papers up, you remove them in the reverse order from which they were added.

There are two basic operations for a stack – push and pop. You will see them in the class below. Push is to add an item to the stack and pop must remove an item from the stack. Before we look at the code below, let me suggest that there are at least two boundary conditions that you must address.

• One cannot pop from an empty stack as there is nothing to pop

• One cannot push to a full stack as there is no more room

This assignment is to implement an integer stack as a class using an array. You must also create a main function to test your implementation. I have provided the class structure below to help you get started. You are required to use this structure for this assignment.

This solution uses tos as the array index to define the stack. When you push you should increment the tos and when you pop you should decrement tos. I suggest that you don’t change the value of tos during the show function as this will really screw you up.

Without further discussion you will find the code for the Stack class on the following page.

#define MAXSIZE 10 //set maximum size of stack to 10 integers

//You probably will want to add an include or two here

class Stack{

private:

int stack[MAXSIZE]; //integer array for your stack

int tos; //array index to top of stack

bool isEmpty(){ if (tos==-1) return true; return false;}

bool isFull(){if (tos == MAXSIZE-1) return true; return false;}

public:

Stack(){tos=-1;} //constructor-initialize tos to -1

//if tos == -1 then stack is empty

void push(int i); //Add i to top of stack;

int pop(); //Remove and return value from top of stack

void show(); //output the stack

};

//your code for push, pop, show, and main goes here

Γλώσσα Προγραμματισμού C Προγραμματισμός C++ CSS HTML5 Visual Basic

Ταυτότητα Εργασίας: #6856076

Σχετικά με την εργασία

8 προτάσεις Απομακρυσμένη εργασία Ενεργό Dec 12, 2014

Ανατέθηκε στον:

cheluxeC

I only ask for 10$. 5$ as initial payment, 5$ as final. The work will be done within 24 hours. If the price and the deadline is acceptable for you, then feel free to contact me for further discussion.

$10 USD σε 1 μέρα
(0 Αξιολογήσεις)
0.0

8 freelancers κάνουν προσφορές κατά μέσο όρο $37 για αυτή τη δουλειά

zhengnami13

Hi. I've read your description, and this is what i'd done at school. I want to help you. I can do this right away. Thank you.

$54 USD σε 1 μέρα
(27 Αξιολογήσεις)
6.4
vietcompro

Hi there, I've already read and understood the project description, and I'm sure I can complete this one for you. So really hope to have chance to work with you, thanks for your consideration! Regards.

$30 USD σε 1 μέρα
(71 Αξιολογήσεις)
5.2
dinhks

A proposal has not yet been provided

$30 USD σε 1 μέρα
(2 Αξιολογήσεις)
2.2
apacherai

I can give you this in few minutes if you want me to do this please ping me. Your work is already done I will send you the screenshot of the working code. Regards

$30 USD σε 1 μέρα
(3 Αξιολογήσεις)
1.6
deepanjanbiswas

I have extensive experience in C,C++ programming. I can easily & reliably do your job with lowest cost & minimum time. Message me.

$20 USD σε 1 μέρα
(1 Κριτική)
1.0
gulshanshaw

Hello, We are expertise Dotnet using VB.net and C#, We also make forms like an international design, Not like classic brown style, But if you want then we can do that too. Our logic are always clear and codes are alway Περισσότερα

$20 USD σε 1 μέρα
(1 Κριτική)
0.6
craigcook

A proposal has not yet been provided

$100 USD σε 1 μέρα
(0 Αξιολογήσεις)
0.0
akashchowdary

I'm an experienced programmer and also have a good knowledge of data structures. So, I think I'm eligible for this job.

$30 USD σε 1 μέρα
(0 Αξιολογήσεις)
0.0