Data Structures programming

I'm a little stuck. I'm getting a few errors and I'm not quite understanding what I'm doing wrong here. I have my code posted. I'm going to have arrows pointed where I'm getting errors and what it's saying"

#include "memoryleakdetect.h" // this must be the first #include in each of your .cpp files
#include "quack.h"

using namespace std;


// change the value of this variable to be your own name instead of "I. Forgot"
const char Quack::YOUR_NAME[] = "I. Forgot";

Quack::Quack(int capacity)
{
items = new item[capacity]; <-----------c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(14): error C2440: '=' : cannot convert from 'Quack::item *' to 'int *'


backPtr = new item;
frontPtr = new item;
midPtr = new item;
current = new item;

maxSize = capacity;
back = maxSize-1;
count = 0;
top = -1;
}

Quack::~Quack(void)
{
delete frontPtr;
delete backPtr;
delete current;
delete midPtr;
delete [] items; //Heap Corruption Debug Error at the end of program.

items = NULL;
maxSize = 0;
back = 0;
}

bool Quack::pushFront(const int n)
{
int i = 0;

if ( count == maxSize ) // Then we cant add to it n e more.
{
throw runtime_error( "Stack is Full" );// Full Stack
return false;
}
backPtr->n = items[back-1];
while ( i < count ) // Loop less than however many we counted.
{
if ( i == top+1 )
{
current->n = items[top+1];
items[top+1] = backPtr->n;
}

midPtr->n = items[++i];
items[i] = current->n;

if ( i != back-1 )
{
current->n = items[++i];
items[i] = midPtr->n;
}
}
++count;
items[top+1] = n;
// return true;
return false;
}

bool Quack::pushBack(const int n)
{
items[count] = n;
count++;
//return true;
return false;
}

bool Quack::popFront(int& n)
{
n = items[top+1];
for ( int i = 0; i < count; i++ )
{
items[i] = items[i+1];
}
count--; // Remove top element.
//return true;
return false;
}

bool Quack::popBack(int& n)
{
n = items[--count];
//return true;
return false;
}

void Quack::rotate(int r)
{
int i = 0;

while ( r > 0 ) // rotate postively.
{
frontPtr->n = items[top+1];
for ( int i = 0; i < back; i++ )
{
items[i] = items[i+1];
}
items[back-1] = frontPtr->n;
r--;
}
while ( r < 0 ) // rotate negatively.
{
if ( i == top+1 )
{
backPtr->n = items[back-1];
current->n = items[top+1];
items[top+1] = backPtr->n;
}
midPtr->n = items[++i];
items[i] = current->n;

if ( i == back-1 )
{
items[back-1] = current->n;
i = 0;
r++; continue;
}
else
{
current->n = items[++i];
items[i] = midPtr->n;
if ( i == back-1 )
{
i = 0;
r++; continue;
}
}
}
}

void Quack::reverse(void)
{
int j = 0; // Variable declaration/initialization.

frontPtr->n = items[top+1];
backPtr->n = items[back-1];

for ( int i = 0; i < count / 2; i++ )
{
items[j] = items[i];
items[i] = items[ count - i-1 ];
items[ count - i-1 ] = items->n; <----------c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(155): error C2227: left of '->n' must point to class/struct/union/generic type
type is 'int *'
}

items[top+1] = backPtr->n;
items[back-1] = frontPtr->n;
}

int Quack::itemCount(void)
{
return count;
}

ostream& operator<<(ostream& out, Quack *q)
{
if ( q.count == 0 ) // No elements have been counted. <---------c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(169): error C2228: left of '.count' must have class/struct/union
type is 'Quack *'
out << endl << "quack: empty" << endl;
else
{
out << endl << "quack: ";
for ( int i = 0; i <
q.count; i++ ) <-----c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(175): error C2228: left of '.count' must have class/struct/union
type is 'Quack *'
{
if ( i < q.count-1 ) <-------c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(175): error C2228: left of '.count' must have class/struct/union
type is 'Quack *'
out << q.items[i] << ", "; <----c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(175): error C2228: left of '.count' must have class/struct/union
type is 'Quack *'
else out << q.items[i]; <------c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(175): error C2228: left of '.count' must have class/struct/union
type is 'Quack *'
}
out << endl << endl;
}
return out;
}

Is there something that I'm missing or I need to fix?
Last edited on
Topic archived. No new replies allowed.