alright im supposed to make a "quack" class (combination of queue and stack). the underlying data struct is a linked list. ive created the quackadt class and override the functions for both other classes (queue class and stack class).
#1) is what im doing so far definitively accurate to the instructions?
#2) getting a lot of errors that i cant debug... ive had a long break in between classes so im rusty and this is due tomorrow, if someone could help point out what im doing wrong thatd be great :))
#3) also my cout function is getting a not defined or declared in this scope even when i include iostream?
this is my "quack" class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#ifndef QUACKADT_H
#define QUACKADT_H
#include <iostream>
#include <cstdlib>
template<class type>
struct node{
type data;
node<type> *link;
};
template<class type>
class quack{
public:
quack();
~quack();
//virtual void initialize()=0;
virtual bool empty() const=0;
virtual void push(const type& element)=0;
//virtual type top() const=0;
virtual type pop()=0;
virtual void enqueue(const type& element)=0;
virtual type dequeue()=0;
private:
node<type> *first;
node<type> *last;
};
template<class type>
quack<type>::quack(){
first=NULL;
}
template<class type>
quack<type>::~quack(){
node<type> *temp;
while(first!=NULL){
temp=first;
first=first->link;
delete temp;
}
};
template<class type>
bool quack<type>::empty() const{
return (first==NULL);
}
template<class type>
void quack<type>::push(const type& element){
node<type> *temp;
temp=new node<type>;
temp->data=element;
temp->link=first;
first=temp;
}
template<class type>
type quack<type>::pop(){
node<type> *temp, *trail;
if(first!=NULL){
temp=first;
trail=first;
first=first->link;
delete temp;
return trail;
}
// else
// cout<<"The list is empty;"<<endl;
}
template<class type>
void quack<type>::enqueue(const type& element){
node<type> *temp;
temp=new node<type>;
temp->data=element;
temp->link=NULL;
if (first==NULL){
first=temp;
last=temp;
}
else{
last->link=temp;
last=last->link;
}
}
template<class type>
type quack<type>::dequeue(){
node<type> *temp, *trail;
if(!empty()){
temp=first;
trail=first;
first=first->link;
delete temp;
if (first==NULL)
last==NULL;
return trail;
}
}
#endif /* QUACKADT_H */
|
declaring an instance i.e.: quack<int> q; results in these errors when i build:
main.cpp:19:16: error: cannot declare variable ‘q’ to be of abstract type ‘quack<int>’
quackADT.h:22:12: note: because the following virtual functions are pure within ‘quack<int>’:
quackADT.h:55:6: note: bool quack<type>::empty() const [with type = int]
quackADT.h:60:6: note: void quack<type>::push(const type&) [with type = int]
quackADT.h:69:6: note: type quack<type>::pop() [with type = int]
quackADT.h:83:6: note: void quack<type>::enqueue(const type&) [with type = int]
quackADT.h:100:6: note: type quack<type>::dequeue() [with type = int]