ADT Reversing Queue() { struct

// This is a code that I put together...when I enter 2 4 6 8 10 I need as an output 10 8 6 4 2.  This algorithm is generating errors.  The errors are listed below.  Please advise.

// revQueue.cpp

#include<iostream.h>

using namespace std;

struct Queue {

int key;
Queue *next;

};

//function proto to print in reverse
void printInReverse(Queue *head);  

int main() {
  int value;
  Queue q;    
  q.append(5);
  q.append(10);
 
  Queue *header = NULL;
  Queue *back = NULL ;
   
   while(! q.empty() )
   {
     q.serve_retrieve(value);
     s.push(value);
   }
   while ( ! s.empty() )
   {
      s.pop_top(value);
      q.append(value);
   }


   for (int i = 1; i < 10 ; i ++) { //loop to populate enqueue

   Queue *newPtr = new Queue;
   newPtr->key = i;
   newPtr->next = NULL;

   if( header == NULL) {header = back = newPtr;}
   
   else {
   back->next = newPtr;
   back = newPtr;
   newPtr = NULL;
   }

 }

    printInReverse(header); // call function to print list in reverse
   
    //printf("\n");
    cout << endl;

    system("pause") ;

    return 0;
}
 
// ******BEGIN function to print in reverse*********

void printInReverse(Queue *head) {
 
   if(head == NULL)

}
   return;
   }
   else {
   printInReverse(head->next) ;
   }

   cout << Head->key ;
}

generated output:

[edeloss2@pegasus exp]$ cxx revQueue.cpp
cxx: Error: revQueue.cpp, line 5: name must be a namespace name
using namespace std;
----------------^
cxx: Error: revQueue.cpp, line 20: class "Queue" has no member "append"
  q.append(5);
----^
cxx: Error: revQueue.cpp, line 21: class "Queue" has no member "append"
  q.append(10);
----^
cxx: Error: revQueue.cpp, line 26: class "Queue" has no member "empty"
   while(! q.empty() )
-------------^
cxx: Error: revQueue.cpp, line 28: class "Queue" has no member
          "serve_retrieve"
     q.serve_retrieve(value);
-------^
cxx: Error: revQueue.cpp, line 29: identifier "s" is undefined
     s.push(value);
-----^
cxx: Error: revQueue.cpp, line 31: identifier "s" is undefined
   while ( ! s.empty() )
-------------^
cxx: Error: revQueue.cpp, line 34: class "Queue" has no member "append"
      q.append(value);
--------^
cxx: Error: revQueue.cpp, line 59: identifier "system" is undefined
    system("pause") ;
----^
cxx: Error: revQueue.cpp, line 70: expected a statement
}
^
cxx: Error: revQueue.cpp, line 71: expected a declaration
   return;
---^
cxx: Error: revQueue.cpp, line 72: expected a declaration
   }
---^
cxx: Warning: revQueue.cpp, line 77: parsing restarts here after previous
          syntax error
   cout << Head->key ;
---------------------^
cxx: Error: revQueue.cpp, line 78: expected a declaration
}
^
cxx: Info: 13 errors detected in the compilation of "revQueue.cpp".


edelossantosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You need to

#include <iostream>

instead of

#include<iostream.h>

Then, 'append()' and 'empty()' are just not defined for

struct Queue {

int key;
Queue *next;

};
0
edelossantosAuthor Commented:
// revQueue.cpp

#include<iostream>

using namespace std;

typedef int Entry_type;
const int maxsize = 20;

struct Queue {

  int key;
  Queue *next;
  void append(const Entry_type &);
  bool empty() const;
  int size() const;
  void display() const;

private:

  int front, rear, count;
  Entry_type queue[maxsize];


};

//function proto to print in reverse
void printInReverse(Queue *head);  

int main() {
  int value;
  Queue q;    
  q.append(5);
  q.append(10);
 
  Queue *header = NULL;
  Queue *back = NULL ;
   Stack s;
   while(!q.empty()) {
     
     q.serve_retrieve(value);
     s.push(value);
   }
   while ( ! s.empty() ) {
     
      s.pop_top(value);
      q.append(value);
   }

   for (int i = 1; i < 10 ; i ++) { //loop to populate enqueue

   Queue *newPtr = new Queue;
   newPtr->key = i;
   newPtr->next = NULL;

   if( header == NULL) {header = back = newPtr;}
   
   else {
   back->next = newPtr;
   back = newPtr;
   newPtr = NULL;
   }

 }

    printInReverse(header); // call function to print list in reverse
   
    //printf("\n");
    cout << endl;

    system("pause") ;

    return 0;
}
 
// ******BEGIN function to print in reverse*********

void printInReverse(Queue *head) {
 
   if(head == NULL)

}
   return;
   }
   else {
   printInReverse(head->next) ;
   }

   cout << Head->key ;
}

void Queue::append(const Entry_type &value) {

  if(full())
    return overflow;
  else {
    rear = ++rear % maxsize;
    queue[rear] = value;
    count++;

  }
  return value;

}

bool Queue::empty() const {

  if(count == 0)
    return true;
  else
    return false;

}
 
int Queue::size() const{return count;}

void Queue::display() const {

  clearScreen();

  for(int i=0; i<maxsize; i++)
    if(queue[i] != -1)
      cout << queue[i] << " ";
    else
      cout << " ";

}

generated output:

[edeloss2@pegasus exp]$ g++ revQueue.cpp
revQueue.cpp: In function `int main()':
revQueue.cpp:38: `Stack' undeclared (first use this function)
revQueue.cpp:38: (Each undeclared identifier is reported only once
revQueue.cpp:38: for each function it appears in.)
revQueue.cpp:38: parse error before `;'
revQueue.cpp:41: no matching function for call to `Queue::serve_retrieve (int &)
'
revQueue.cpp:42: `s' undeclared (first use this function)
revQueue.cpp:71: implicit declaration of function `int system(...)'
revQueue.cpp: In function `void printInReverse(Queue *)':
revQueue.cpp:82: parse error before `}'
revQueue.cpp:82: confused by earlier errors, bailing out

0
jkrCommented:
>>revQueue.cpp:38: `Stack' undeclared (first use this function)

The compiler is right, there is no previous declaration for "Stack" in the code you posted. Maybe there's just a header file missing.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

edelossantosAuthor Commented:
// I made a change.

// revQueue.cpp

#include<iostream>

using namespace std;

typedef int Entry_type;
const int maxsize = 20;

struct Queue {

  int key;
  Queue *next;
  void append(const Entry_type &);
  bool empty() const;
  int size() const;
  void display() const;

private:

  int front, rear, count;
  Entry_type queue[maxsize];


};

//function proto to print in reverse
void printInReverse(Queue *head);  

int main() {
  int value;
  Queue q;    
  q.append(5);
  q.append(10);
 
  Queue *header = NULL;
  Queue *back = NULL ;
   int s;
   while(!q.empty()) {
     
     q.serve_retrieve(value);
     s.push(value);
   }
   while ( ! s.empty() ) {
     
      s.pop_top(value);
      q.append(value);
   }

   for (int i = 1; i < 10 ; i ++) { //loop to populate enqueue

   Queue *newPtr = new Queue;
   newPtr->key = i;
   newPtr->next = NULL;

   if( header == NULL) {header = back = newPtr;}
   
   else {
   back->next = newPtr;
   back = newPtr;
   newPtr = NULL;
   }

 }

    printInReverse(header); // call function to print list in reverse
   
    //printf("\n");
    cout << endl;

    //const system("pause") ;

    return 0;
}
 
// ******BEGIN function to print in reverse*********

void printInReverse(Queue *head) {
 
   if(head == NULL)

}
   return;
   }
   else {
   printInReverse(head->next) ;
   }

   cout << Head->key ;
}

void Queue::append(const Entry_type &value) {

  if(full())
    return overflow;
  else {
    rear = ++rear % maxsize;
    queue[rear] = value;
    count++;

  }
  return value;

}

bool Queue::empty() const {

  if(count == 0)
    return true;
  else
    return false;

}
 
int Queue::size() const{return count;}

void Queue::display() const {

  clearScreen();

  for(int i=0; i<maxsize; i++)
    if(queue[i] != -1)
      cout << queue[i] << " ";
    else
      cout << " ";

}

output:

[edeloss2@pegasus exp]$ g++ revQueue.cpp
revQueue.cpp: In function `int main()':
revQueue.cpp:41: no matching function for call to `Queue::serve_retrieve (int &)
'
revQueue.cpp:42: request for member `push' in `s', which is of non-aggregate typ
e `int'
revQueue.cpp:44: request for member `empty' in `s', which is of non-aggregate ty
pe `int'
revQueue.cpp:46: request for member `pop_top' in `s', which is of non-aggregate
type `int'
revQueue.cpp: In function `void printInReverse(Queue *)':
revQueue.cpp:82: parse error before `}'
revQueue.cpp:82: confused by earlier errors, bailing out

0
jkrCommented:
You are apparently believing in the success of salami tactics? :o)

Well, now we're getting further, but as gcc states:

revQueue.cpp:41: no matching function for call to `Queue::serve_retrieve (int &)

That class does not have such a member function (so far)
0
edelossantosAuthor Commented:
// revQueue.cpp

#include <iostream>

using namespace std;

typedef int Entry_type;
const int maxsize = 20;

struct Queue {

  int key;
  Queue *next;
  void append(const Entry_type &);
  void pop();
  void push(const Entry_type &);
  void pop_top(Entry_type &);
  void serve_retrieve(Entry_type &);
  void top(Entry_type &) const;
  bool empty() const;
  bool full() const;
  int size() const;
  void display() const;

private:

  int front, rear, count, stack_top;
  Entry_type queue[maxsize];

};

//function proto to print in reverse
void printInReverse(Queue *head);  

int main() {
  int value;
  Queue q;    
  q.append(5);
  q.append(10);
 
  Queue *header = NULL;
  Queue *back = NULL ;
   int s;
   while(!q.empty()) {
     
     q.serve_retrieve(value);
     s.push(value);
   }
   while ( ! s.empty() ) {
     
      s.pop_top(value);
      q.append(value);
   }

   for (int i = 1; i < 10 ; i ++) { //loop to populate enqueue

   Queue *newPtr = new Queue;
   newPtr->key = i;
   newPtr->next = NULL;

   if( header == NULL) {header = back = newPtr;}
   
   else {
   back->next = newPtr;
   back = newPtr;
   newPtr = NULL;
   }

 }

    printInReverse(header); // call function to print list in reverse
   
    //printf("\n");
    cout << endl;

    //const system("pause") ;

    return 0;
}
 
// ******BEGIN function to print in reverse*********

void printInReverse(Queue *head) {
 
   if(head == NULL)

}
   return;
   }
   else {
   printInReverse(head->next) ;
   }

   cout << Head->key ;
}

void Queue::append(const Entry_type &value) {

  if(full())
    return overflow;
  else {
    rear = ++rear % maxsize;
    queue[rear] = value;
    count++;

  }
  return value;

}

bool Queue::empty() const {

  if(count == 0)
    return true;
  else
    return false;

}

bool Queue::full() const {

  if(count == maxsize)
    return true;
  else
    return false;

}
 
int Queue::size() const{return count;}

void Queue::display() const {

  clearScreen();

  for(int i=0; i<maxsize; i++)
    if(queue[i] != -1)
      cout << queue[i] << " ";
    else
      cout << " ";

}

void Queue::serve_retrieve(Entry_Type &value) {

  if(empty())
    return underflow;
  else {
    value = queue[front];
    front = (++front) % maxsize;
    count--;

  }
  return value;

}

void Queue::pop_top(Entry_type &value) {

  if(stack_top == 0)
    return underflow;
  else {
    value = stack[stack_top--];

  }
  return value;

}

void Queue::push(const Entry_type &value) {

  if(stack_top >= maxsize - 0)
    return overflow;
  else
    stack[++stack_top] = value;
    return value;

}

void Queue::pop() {

  if(stack_top == 0)
    return underflow;
  else
    stack_top--;
    return value;

}

void Queue::top(Entry_type &value) const {

  if(stack_top == 0)
    return underflow;
  else
    value = stack[stack_top];
    return value;

}
 
output:

[edeloss2@pegasus exp]$ g++ revQueue.cpp
revQueue.cpp: In function `int main()':
revQueue.cpp:47: request for member `push' in `s', which is of non-aggregate typ
e `int'
revQueue.cpp:49: request for member `empty' in `s', which is of non-aggregate ty
pe `int'
revQueue.cpp:51: request for member `pop_top' in `s', which is of non-aggregate
type `int'
revQueue.cpp: In function `void printInReverse(Queue *)':
revQueue.cpp:87: parse error before `}'
revQueue.cpp:87: confused by earlier errors, bailing out

// I do not understand these.  I thought I had repaired with the new implementations.




0
edelossantosAuthor Commented:
jkr,

I've tried to repair the codes myself and I am stuck.  Please advise when you can.  Sorry about the salami tactics.  Del
0
jkrCommented:
In

 int value;
 Queue q;    
 q.append(5);
 q.append(10);
 
 Queue *header = NULL;
 Queue *back = NULL ;
   int s;
  while(!q.empty()) {
   
     q.serve_retrieve(value);
    s.push(value);
  }
  while ( ! s.empty() ) {
   
      s.pop_top(value);
     q.append(value);
  }

's' is an integer, which you cannot use as a queue. Did you mean

   Queue s;
  while(!q.empty()) {
   
     q.serve_retrieve(value);
    s.push(value);
  }
  while ( ! s.empty() ) {
   
      s.pop_top(value);
     q.append(value);
  }

?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.