stackqueue

hello so i am trying to do this

Please HELP!!!!! i hope someone can help im really struggling with this.

----------------------------------

write a class WeirdIntStack that implements our stack ADT, but which is only allowed to use queues in the implementation. Your implementation is not allowed to use objects of any kind other than queues, and you are not allowed to use arrays. Integer-type variables are allowed.

The class should contain the following:

a default constructor
a copy constructor
a destructor
the methods getSize, isEmpty, push, pop and getTop that have the effect described in our ADT.
I also require that your implementation of pop and getTop run in
O(1)
time. I have no other requirements on the other methods, except that they should not be unnecessarily slow.
You should use the STL implementation of queues. Note that no assignment operator is implemented, so copies of queues must be made manually.

Hint: You should only need one queue in your class member variables, but some of your methods will require an additional queue as temporary storage.


------------------------------------
CPP file
----------------------------------
//
#include <cstdlib> //Used for NULL
#include <vector> //Try-Catch statement
#include "WeirdIntStack.h"
using namespace std;

WeirdIntStack::WeirdIntStack() {
this->size = 0;
this->head = nullptr;
this->tail = nullptr;
}
int WeirdIntStack::getSize() {
//if (this->size == nullptr)
return this->size;
}

//-------------------------------------------------------------------------
bool WeirdIntStack::IsEmpty(){
if(this->size == 0)
return true;
return false;

}
//-------------------------------------------------------------------------
bool WeirdIntStack::Push(TYPE item) //Adding an item to the list (at the top)
{
if (IsFull() == false)
{
NodePtr n = new Node; //Adding a new link to the list
n->next = head; //Setting pointer to the front of the list
n->data = item; //Setting that new pointer's data
head = n; //Setting the head to the new beginning of the list
return true;
}
return false; //If failed to add item, something like it being full
}

void WeirdIntStack::Pop() {

//queue<int> myqueue

this.back()


// TYPE item; //Getting a new item of TYPE
// if (!IsEmpty()) {
// Delete = head; //Setting delete to the head of the stack
// Deleting the node
//
// } else if (head->next == NULL && head->data != NULL) {
// item = head->data;
// delete Delete;
// head = NULL;
// }
// return item;
}
//
-------------------------------------------------------------------------------

.h File

------------------------------------------------

//
#ifndef PROJECT6_WEIRDINTSTACK_H
#define PROJECT6_WEIRDINTSTACK_H

#endif //PROJECT6_WEIRDINTSTACK_H
#include <utility>
#include <string>

typedef int TYPE; //Declaring a changable type

typedef struct Node //Creating the basic structure of the links
{
TYPE data;
Node* next;
}*NodePtr; //The name of the new pointer type

class WeirdIntStack
{
// queue<int> q1;


protected:
int size;

public:
WeirdIntStack();
WeirdIntStack(WeirdIntStack& toCopy);
~WeirdIntStack();



int getSize();

bool IsEmpty() { if (head == NULL){ return true; } else return false; };

bool IsFull();

bool Push(TYPE item);

void Pop ();


TYPE Top() { return (head->data); };
private:
NodePtr head; //Head pointer holding data and next pointer
};
Last edited on
Spamming your question won't make people reply quicker.
http://www.cplusplus.com/forum/general/253398/

It might make it worse.
sorry but please help
> Spamming your question won't make people reply quicker.
> http://www.cplusplus.com/forum/general/253398/
that's a completely different question, ¿so what's your point?


@OP: write a freaking damn question, ¿what do you need help with?

> You should use the STL implementation of queues
> You should only need one queue in your class member variables
perhaps you should read your assignment.


edit: ¿why is this in the lounge?
Last edited on
Topic archived. No new replies allowed.