Data Structures programming

I'm a little stuck on my programming.This is a list of the errors that I keep getting:
ke\quake\quack.cpp(13): error C2440: '=' : cannot convert from 'Quack::item *' to 'int'
There is no context in which this conversion is possible
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(31): error C2541: 'delete' : cannot delete objects that are not pointers
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(47): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(47): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(52): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(52): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(53): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(53): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(56): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(56): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(57): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(57): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(61): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(61): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(62): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(62): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(66): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(66): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(73): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(73): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(81): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(81): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(84): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(84): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(93): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(93): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(104): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(104): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(107): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(107): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(109): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(109): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(116): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(116): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(117): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(117): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(118): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(118): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(120): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(120): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(121): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(121): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(125): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(125): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(131): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(131): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(132): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(132): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(146): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(146): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(147): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(147): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(151): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(151): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(151): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(151): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(152): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(152): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(152): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(152): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(153): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(153): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(153): error C2227: left of '->n' must point to class/struct/union/generic type
type is 'int'
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(156): error C2109: subscript requires array or pointer type
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(156): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(157): error C2109: subscript requires array or pointer type

Here is the rest of the errors. It was to long:
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(157): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(167): error C2228: left of '.count' must have class/struct/union
type is 'Quack *'
did you intend to use '->' instead?
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(172): error C2228: left of '.count' must have class/struct/union
type is 'Quack *'
did you intend to use '->' instead?
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(174): error C2228: left of '.count' must have class/struct/union
type is 'Quack *'
did you intend to use '->' instead?
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(175): error C2228: left of '.items' must have class/struct/union
type is 'Quack *'
did you intend to use '->' instead?
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(175): error C2228: left of '.n' must have class/struct/union
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(176): error C2228: left of '.items' must have class/struct/union
type is 'Quack *'
did you intend to use '->' instead?
c:\users\brian williams\desktop\260\lab2\quake\quake\quack.cpp(176): error C2228: left of '.n' must have class/struct/union

Here is the code for the folder. If you need the code for the rest of the project, let me know:


#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];
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].n;
while ( i < count ) // Loop less than however many we counted.
{
if ( i == top+1 )
{
current->n = items[top+1].n;
items[top+1].n = backPtr->n;
}

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

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

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

bool Quack::popFront(int& n)
{
n = items[top+1].n;
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].n;
return true;
//return false;
}

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

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

if ( i == back-1 )
{
items[back-1].n = current->n;
i = 0;
r++; continue;
}
else
{
current->n = items[++i].n;
items[i].n = 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].n;
backPtr->n = items[back-1].n;

for ( int i = 0; i < count / 2; i++ )
{
items[j].n = items[i].n;
items[i].n = items[ count - i-1 ].n;
items[ count - i-1 ].n = items->n;
}

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

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

ostream& operator<<(ostream& out, Quack *q)
{
if ( q.count == 0 ) // No elements have been counted.
out << endl << "quack: empty" << endl;
else
{
out << endl << "quack: ";
for ( int i = 0; i < q.count; i++ )
{
if ( i < q.count-1 )
out << q.items[i].n << ", ";
else out << q.items[i].n;
}
out << endl << endl;
}
return out;
}
Nice, I get errors sometimes too. You need to fix those before the program gets compiled, just in case you didn't know.

Next time you want REAL help, post the code giving the errors so we can actually see what your doing wrong.
I have the code posted.
bwill31, go back and edit your post to put the code in [ code ] //Code Here [ / code ] brackets.

1
2
3
4
5
6
7
8
#include <iostream>

using namespace std;

int main(){
    cout << "This will clean up your post considerably!" << endl;
    return 0;
}
ciphermagi, I have that in my driver folder. It all runs together. Here is my code for my project:

quack.h


#pragma once

#include <ostream>

class Quack
{
public:
static const char YOUR_NAME[]; // used for printing out programmer's name

Quack(int capacity);
~Quack(void);
bool pushFront(const int n); // push an item onto the front
bool pushBack(const int n); // push an item onto the back
bool popFront(int& n); // pop an item off the front
bool popBack(int& n); // pop an item off the back
void rotate(int r); // "rotate" the stored items (see note below)
void reverse(void); // reverse the order of the stored items
int itemCount(void); // return the current number of stored items

private:
int items; // pointer to storage for the circular array.
// Each item in the array is an int.

int maxSize; // is for the size of the item stack
int back; // is for the back or "bottom" of the stack
int count; // to count the items added to the stack
int top;

struct item // Definition of each item stored by the quack.
{
int n;
};

//item *items; // Pointer to storage for the circular array.
item *backPtr;
item *frontPtr;
item *midPtr;
item *current; // Each item in the array is an int.

public:
friend std::ostream& operator<<(std::ostream& out, Quack *q);
};


lab2driver.cpp

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

using namespace std;

const static int QUACK_SIZE = 7;
static Quack *quack;

static void push(Quack *quack, bool front, int n)
{
bool ok;

if (front)
ok = quack->pushFront(n);
else
ok = quack->pushBack(n);
cout << ">>> push" << (front ? "Front " : "Back ") << n << (ok ? " succeeded" : " failed") << endl;
}

static void pop(Quack *quack, bool front)
{
bool ok;
int n;

if (front)
ok = quack->popFront(n);
else
ok = quack->popBack(n);
cout << ">>> pop" << (front ? "Front " : "Back ");
if (ok)
cout << "succeeded: " << n;
else
cout << "failed";
cout << endl;
}

int main(int argc, char **argv)
{
cout << "CS260 - Lab2 - " << Quack::YOUR_NAME << endl << endl;

quack = new Quack(QUACK_SIZE);
cout << quack;
push(quack, true, 1);
push(quack, true, 2);
push(quack, true, 3);
push(quack, true, 4);
push(quack, false, 0);
push(quack, true, 9);
cout << quack;
cout << "--- # of items: " << quack->itemCount() << endl << endl;
pop(quack, true);
cout << quack;
pop(quack, true);
cout << quack;
push(quack, false, 7);
cout << quack;
push(quack, false, 8);
cout << quack;
cout << ">>> rotate(2)" << endl;
quack->rotate(2);
cout << quack;
cout << ">>> rotate(-3)" << endl;
quack->rotate(-3);
cout << quack;
cout << ">>> reverse" << endl;
quack->reverse();
cout << quack;
push(quack, true, 6);
cout << quack;
cout << ">>> rotate(3)" << endl;
quack->rotate(3);
cout << quack;
cout << ">>> rotate(-4)" << endl;
quack->rotate(-4);
cout << quack;
cout << "--- # of items: " << quack->itemCount() << endl << endl;
while (quack->itemCount() > 0) {
pop(quack, false);
cout << quack;
}
cout << "--- # of items: " << quack->itemCount() << endl << endl;

delete quack;

// report on memory leaks in the Output Window
#ifdef _DEBUG
if (argc == 2) {
_CrtSetReportMode( _CRT_WARN , _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN , _CRTDBG_FILE_STDERR );
}
_CrtDumpMemoryLeaks();
#endif

return 0;
}

memoryleakdetect.h


#pragma once // include this .h file file only once

// enable Visual C++ memory leak checking
#ifdef _DEBUG
#include <ostream>
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif


Nevermind...I don't know why I even try sometimes.
I guess I'm a little confused then what your saying.
I'm saying it's making my eyes cross trying to read code that's all left justified and not even slightly separated (one file from another) by some sort of break, and that's not even bringing up the fact that this forum has a built in function, which I described to you, on making code actually show up in the same colour and format that it would in a compileran IDE, which makes it incredibly easy to read.
Last edited on
Thought I should clear the confusion here by re-posting the code in the preferred format, because I am finding it hard to read too:

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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

quack.h
#pragma once

#include <ostream>

class Quack
{
public:
static const char YOUR_NAME[]; // used for printing out programmer's name

Quack(int capacity);
~Quack(void);
bool pushFront(const int n); // push an item onto the front
bool pushBack(const int n); // push an item onto the back
bool popFront(int& n); // pop an item off the front
bool popBack(int& n); // pop an item off the back
void rotate(int r); // "rotate" the stored items (see note below)
void reverse(void); // reverse the order of the stored items
int itemCount(void); // return the current number of stored items

private:
int items; // pointer to storage for the circular array.
// Each item in the array is an int.

int maxSize; // is for the size of the item stack
int back; // is for the back or "bottom" of the stack
int count; // to count the items added to the stack
int top;

struct item // Definition of each item stored by the quack.
{
int n;
};

//item *items; // Pointer to storage for the circular array.
item *backPtr;
item *frontPtr;
item *midPtr;
item *current; // Each item in the array is an int.

public:
friend std::ostream& operator<<(std::ostream& out, Quack *q);
};


lab2driver.cpp

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

using namespace std;

const static int QUACK_SIZE = 7;
static Quack *quack;

static void push(Quack *quack, bool front, int n)
{
bool ok;

if (front)
ok = quack->pushFront(n);
else
ok = quack->pushBack(n);
cout << ">>> push" << (front ? "Front " : "Back ") << n << (ok ? " succeeded" : " failed") << endl;
}

static void pop(Quack *quack, bool front)
{
bool ok;
int n;

if (front)
ok = quack->popFront(n);
else
ok = quack->popBack(n);
cout << ">>> pop" << (front ? "Front " : "Back ");
if (ok)
cout << "succeeded: " << n;
else
cout << "failed";
cout << endl;
}

int main(int argc, char **argv)
{
cout << "CS260 - Lab2 - " << Quack::YOUR_NAME << endl << endl;

quack = new Quack(QUACK_SIZE);
cout << quack;
push(quack, true, 1);
push(quack, true, 2);
push(quack, true, 3);
push(quack, true, 4);
push(quack, false, 0);
push(quack, true, 9);
cout << quack;
cout << "--- # of items: " << quack->itemCount() << endl << endl;
pop(quack, true);
cout << quack;
pop(quack, true);
cout << quack;
push(quack, false, 7);
cout << quack;
push(quack, false, 8);
cout << quack;
cout << ">>> rotate(2)" << endl;
quack->rotate(2);
cout << quack;
cout << ">>> rotate(-3)" << endl;
quack->rotate(-3);
cout << quack;
cout << ">>> reverse" << endl;
quack->reverse();
cout << quack;
push(quack, true, 6);
cout << quack;
cout << ">>> rotate(3)" << endl;
quack->rotate(3);
cout << quack;
cout << ">>> rotate(-4)" << endl;
quack->rotate(-4);
cout << quack;
cout << "--- # of items: " << quack->itemCount() << endl << endl;
while (quack->itemCount() > 0) {
pop(quack, false);
cout << quack;
}
cout << "--- # of items: " << quack->itemCount() << endl << endl;

delete quack;

// report on memory leaks in the Output Window
#ifdef _DEBUG
if (argc == 2) {
_CrtSetReportMode( _CRT_WARN , _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN , _CRTDBG_FILE_STDERR );
}
_CrtDumpMemoryLeaks();
#endif

return 0;
}

memoryleakdetect.h


#pragma once // include this .h file file only once

// enable Visual C++ memory leak checking
#ifdef _DEBUG
#include <ostream>
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif 



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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#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];
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].n;
while ( i < count ) // Loop less than however many we counted.
{
if ( i == top+1 )
{
current->n = items[top+1].n;
items[top+1].n = backPtr->n;
}

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

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

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

bool Quack::popFront(int& n)
{
n = items[top+1].n;
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].n;
return true;
//return false;
}

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

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

if ( i == back-1 )
{
items[back-1].n = current->n;
i = 0;
r++; continue;
}
else
{
current->n = items[++i].n;
items[i].n = 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].n;
backPtr->n = items[back-1].n;

for ( int i = 0; i < count / 2; i++ )
{
items[j].n = items[i].n;
items[i].n = items[ count - i-1 ].n;
items[ count - i-1 ].n = items->n;
}

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

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

ostream& operator<<(ostream& out, Quack *q)
{
if ( q.count == 0 ) // No elements have been counted.
out << endl << "quack: empty" << endl;
else
{
out << endl << "quack: ";
for ( int i = 0; i < q.count; i++ )
{
if ( i < q.count-1 )
out << q.items[i].n << ", ";
else out << q.items[i].n;
}
out << endl << endl;
}
return out;
}
closed account (1yR4jE8b)
Your code is still practically unreadable because of the lack of indentation.
Topic archived. No new replies allowed.