I am getting a access violation error in my code when I try run it. The program is a priority queue that inserts a value and prints the heap after each insertion and min extract.
Header File:
#pragma once
/*
Header file for the priority queue class
*/
#ifndef PRIORITYQUEUE_H
#define PRIORITYQUEUE_H
class priorityQueue
{
private:
int size;
int *data;
public:
static const int CAPACITY = 50;
priorityQueue();//constructor
~priorityQueue();//destructor
int getParent(int index);
int getLeftChild(int index);
int getRightChild(int index);
void swap(int &, int &);
void insert(int item); //enqueue - heap_insert
void printArray(int []);
void heapify(int index);
//remove and return the smallest item currently in the priority queue
int extractMin();//dequeue
bool empty() const;
int min() const; //return the smallest item
};
#endif
Main Code:
#include <iostream>
#include "priorityQueue.h"
using namespace std;
int main()
{
priorityQueue myqueue; //class object
if (myqueue.empty())
cout << "My priority Queue is empty\n" << endl; //prompt
myqueue.insert(59); //Insert value into queue
cout << "After inserting 59 Priority Queue has" << endl;
myqueue.insert(41);
cout << "After inserting 41 Priority Queue has" << endl;
myqueue.insert(25);
cout << "After inserting 25 Priority Queue has" << endl;
myqueue.insert(12);
cout << "After inserting 12 Priority Queue has" << endl;
myqueue.insert(91);
cout << "After inserting 91 Priority Queue has" << endl;
myqueue.min();
myqueue.extractMin();
cout << "After extracting the minimum value Priority Queue has" << endl;
myqueue.insert(34);
cout << "After inserting 34 Priority Queue has" << endl;
myqueue.insert(63);
cout << "After inserting 63 Priority Queue has" << endl;
myqueue.extractMin();
cout << "After extracting the minimum value Priority Queue has" << endl;
myqueue.insert(75);
cout << "After inserting 75 Priority Queue has" << endl;
myqueue.insert(85);
cout << "After inserting 85 Priority Queue has" << endl;
myqueue.extractMin();
cout << "After extracting the minimum value Priority Queue has" << endl;
cout <<"Minimum value is " ;
cout << myqueue.min() <<endl; //prints out heap min
system("pause");
return 0;
}
priorityQueue::priorityQueue() //constructor
{
size = CAPACITY;
&data[size];
}
priorityQueue::~priorityQueue() //destructor
{
}
int priorityQueue::getParent(int index) //finds parent
{
return (index - 1) / 2;
}
int priorityQueue::getLeftChild(int index) //finds left child
{
return (2 * index) + 1;
}
int priorityQueue::getRightChild(int index) //find right child
{
return (2 * index) + 2;
}
void priorityQueue::swap(int& item1, int& item2) //swaps value of two variables
{
int temp = item1;
item1 = item2;
item2 = temp;
}
void priorityQueue::heapify(int index) //heapifies the heap
{
int largest = index;
int l = getLeftChild(index);
int r = getRightChild(index);
if (l < size && data[l] > data[index])
{
largest = l;
}
if (r < size && data[r] > data[largest])
{
largest = r;
}
if (largest != index)
{
swap(data[index], data[largest]);
heapify(data[size]);
}
}
void priorityQueue::printArray(int []) //prints array
{
for (int i = 0; i < CAPACITY; i++)
{
cout << data[i] << ", ";
}
}
int priorityQueue::extractMin() //finds min and removes it
{
int min = data[0];
data[0] = data[size - 1];
size - 1;
heapify(data[size]);
return min;
}
int priorityQueue::min() const // finds min
{
return data[0];
}
bool priorityQueue::empty() const // checks if heap is empty
{
if (data == NULL)
{
return true;
}
else
{
return false;
}
}
void priorityQueue::insert(int Item) //inserts values into heap
{
size += 1;
int i = size - 1;
while (i > 0 && data[getParent(i)] < Item)
{
data[i] = data[getParent(i)];
i = getParent(i);
}
data[i] = Item;
}
In your constructor, &data[size]; does nothing. You need to allocate some memory for it, possibly using new - data = new int[size] - or use a smart pointer.
Related
The issue is portrayed clearly in the display function.I wanted to display the array items in top, but I couldn't figure out a way to do so as it was constantly being incremented.
Instead of this...:
void CircularQueue :: Display() const {
for(int i = front; i < MAX; i++) {
cout << a[i] << endl;
}
}
**I want to display the circular queue using top:**
void CircularQueue :: Display() const {
for(int i = front; i < top; i++) {
cout << a[i] << endl;
}
}
In my main function, I enqueue'd 15 items, and as a result, top incremented 15 times. So obviously there would be 5 garbage values. How can I manipulate top so that the display function shows all 10 array values?
#include <iostream>
using namespace std;
#define MAX 10
class CircularQueue {
private:
int top;
int front;
public:
//assume that the max number of items in this circular queue is 10.
int a[MAX];
CircularQueue() {top = -1; front = -1;}
int enqueue(int x);
void dequeue();
void peekFront() const;
void peekBack() const;
void Display() const;
bool isEmpty();
};
//1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
//10,11,12,13,14,15,6,7,8,9
int CircularQueue :: enqueue(int x) {
//Problem: The array is actually growing in size.
++top;
a[top%10] = x;
int y = a[top%10];
cout << "Adding " << y << " to the queue." << endl;
if(top == 0) {
front = 0;
}
return y;
}
void CircularQueue :: dequeue() {
if(top < 0) {
cout << "The queue is empty." << endl;
} else {
int x = a[top];
cout << x << " will now be removed." << endl;
for(int i = 0; i <= top - 1; i++) {
a[i] = a[i+1];
}
top--;
x = a[top];
cout << "The last element of the queue is now: " << x << endl;
}
}
bool CircularQueue :: isEmpty() {
return top < 0;
}
void CircularQueue :: peekFront() const {
if(front < 0) {
cout << "The queue is empty." << endl;
} else {
int x = a[front];
cout << "The Front value is: " << x << endl;
}
}
void CircularQueue :: peekBack() const {
if(top < 0) {
cout << "The queue is empty." << endl;
} else {
int x;
x = a[top];
cout << "The back value is: " << a[top] << endl;
}
}
void CircularQueue :: Display() const {
for(int i = front; i < MAX; i++) {
cout << a[i] << endl;
}
}
int main() {
CircularQueue Aq;
Aq.enqueue(0);
Aq.enqueue(1);
Aq.enqueue(2);
Aq.enqueue(3);
Aq.enqueue(4);
Aq.enqueue(5);
Aq.enqueue(6);
Aq.enqueue(7);
Aq.enqueue(8);
Aq.enqueue(9); Aq.Display();
Aq.enqueue(10);
Aq.enqueue(11);
Aq.enqueue(12);
Aq.enqueue(13);
Aq.enqueue(14);
Aq.enqueue(15); Aq.Display();
return 0;
}
Expected output should be:
10,11,12,13,14,15,6,7,8,9
The array size should be 10 always. But when I keep enqueueing; The array size goes beyond 10.
This program is supposed to create three arrays of class object My_array. The first array is filled with random numbers. The second array is an exact copy of the first. The third array is entered by the user. The program checks to make sure that the first two arrays indeed equal each other and then it check to the hamming distance of the first and third array. The professor defines the hamming distance as each part off the array that is different.
My problem has been getting hamming to work. I actually have a hard time with operating overloading so I am surprised that works (well I have no errors showing in VS Studio) but not the hamming part. Any help would be appreciated. There are three files in order: main.cpp, my_array.cpp, and my_array.h. Function definitions and declarations were provided by professor. I am required to insert how each function operates.
#include "my_array.h"
#include <iostream>
using namespace std;
int main()
{
int size;
cout << "How big of an array shall we work with? ";
cin >> size;
My_array a(size);
My_array b(size);
My_array c(size);
a.randomize(100);
b = a;
c.input();
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << "a != b: " << (a != b) << endl;
cout << "a == b: " << (a == b) << endl;
cout << "The hamming distance is: " << a.hamming(c);
return 0;
}
#include "my_array.h"
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
// Constructor
My_array::My_array(int the_size)
{
array = NULL;
size = 0;
resize(the_size);
}
// Destructor.
My_array::~My_array()
{
empty();
}
// Copy constructor
My_array::My_array(My_array &data)
: size(data.size)
{
array = new int[size];
for (int i = 0; i<size; i++)
array[i] = data.array[i];
}
// Overloaded assignment operator.
My_array &My_array::operator=(My_array &data)
{
if (this != &data) {
resize(data.size);
for (int i = 0; i<size; i++)
array[i] = data.array[i];
}
else
cout << "Attempt to copy an object on itself. "
<< "Operation ignored." << endl;
return *this;
}
void My_array::input()
{
int j;
cout << "Please enter " << size << " numbers.\n";
for (int i = 0; i < size; i++)
{
cout << "Number " << i + 1 << ": ";
cin >> j;
array[i] = j;
}
}
void My_array::randomize(int limit)
{
srand(time(NULL));
for (int i = 0; i < size; i++)
array[i] = rand() % limit + 1;
}
bool My_array::operator ==(My_array &data)
{
if(this->size != data.size)
return false;
for (int i = 0; i <size; i++)
{
if (*this[i].array != data.array[i])
return false;
}
return true;
}
bool My_array::operator !=(My_array &data)
{
if (*this == data)
return false;
return true;
}
int My_array::hamming(My_array &data)
{
int ham = 0;
for (int i = 0; i < size; i++)
if (*this[i].array != data[i].array)
ham++;
return ham;
}
// This function will empty the target object
void My_array::empty()
{
if (size != 0 && array != NULL) {
size = 0;
delete[] array;
}
}
// Resize the array.
void My_array::resize(int the_size)
{
if (size >= 0) {
empty();
if (the_size != 0) {
size = the_size;
array = new int[size];
}
}
else
cout << "Resize attepmted with a negative size. "
<< "Operation ignored." << endl;
}
// Access an element of the array.
int &My_array::operator[](int index)
{
if (index < size)
return array[index];
else {
cerr << "Illegal access to an element of the array." << endl
<< "The size of the array was " << size
<< " and the index was " << index << endl;
exit(1);
}
}
// Accessor
int My_array::get_size()
{
return size;
}
void My_array::output()
{
cout << "The array of size " << size
<< " contains the elements:" << endl;
for (int i = 0; i<size; i++)
cout << array[i] << ' ';
cout << endl;
}
//overloading the << operator.
ostream &operator<<(ostream &out, My_array &data)
{
out << "The array of size " << data.size
<< " contains the elements:" << endl;
for (int i = 0; i<data.size; i++)
out << data.array[i] << ' ';
out << endl;
return out;
}
#ifndef MY_ARRAY_H
#define MY_ARRAY_H
#include <iostream>
using namespace std;
class My_array {
protected:
int size;
int *array;
public:
// Constructor
My_array(int the_size = 0);
// Destructor
~My_array();
// Copy constructor
My_array(My_array &data);
// Assignment operator
My_array &operator=(My_array &data);
void input();
void randomize(int limit);
bool operator ==(My_array &data);
bool operator !=(My_array &data);
int hamming(My_array &data);
// Deletes the array
void empty();
// Resize the array.
void resize(int the_size = 0);
// Access an element of the array.
int &operator[](int index);
// Returns the size of the array.
int get_size();
// Output the elements of the array.
void output();
friend ostream &operator<<(ostream &out, My_array &data);
};
#endif
This:
*this[i].array != data[i].array
should be this:
array[i] != data.array[i]
or this:
array[i] != data[i]
The *this is unnecessary, and data[i] is a reference to an int (the same one you get by calling data.array[i], thanks to your operator[]), and an int has no member called "array".
I just have a few errors of the same type in my main program. My college professor is not answering my emails so I have to resort to asking you guys. In my main program I have several errors somewhat similar to this: "request for member which is of non-class type." Program01 is basically testing every function in ListType.h, OListType.h, and UListType.h to make sure everything works correctly. Any help you can provide in a timely fashion will be appreciated.
Here is ListType.h:
#ifndef LISTTYPE_H_INCLUDED
#define LISTTYPE_H_INCLUDED
#include <iostream>
class ListType {
public:
ListType(size_t=10);
ListType(const ListType&);
virtual ~ListType();
virtual bool insert(int)=0;
virtual bool eraseAll();
virtual bool erase(int)=0;
virtual bool find(int) const=0;
size_t size() const;
bool empty() const;
bool full() const;
friend std::ostream& operator << (std::ostream&, const ListType&);
const ListType& operator= (const ListType&);
protected:
int *items;
size_t capacity;
size_t count;
};
#endif // LISTTYPE_H_INCLUDED
Here is ListType.cpp:
#include "ListType.h"
ListType::ListType (size_t a) {
capacity = a;
count = 0;
items = new int [capacity];
}
ListType::ListType(const ListType& newlist) {
capacity = newlist.capacity;
count = newlist.count;
items = new int [capacity];
for (size_t i = 0; i < count; ++i)
items[i] = newlist.items[i];
}
ListType::~ListType() {
delete [] items;
}
bool ListType::eraseAll() {
count = 0;
return 0;
}
size_t ListType::size() const {
return (count);
}
bool ListType::empty() const {
return (count == 0);
}
bool ListType::full() const {
return (count == capacity);
}
std::ostream& operator << (std::ostream& out, const ListType& my_list) {
if (!my_list.empty()) {
for (size_t i = 0; i < my_list.count; ++i){
out << my_list.items[i] << ',';
}
}
return out;
}
const ListType& ListType::operator= (const ListType& rightObject) {
if (this != & rightObject) {
delete [] items;
capacity = rightObject.capacity;
count = rightObject.count;
items = new int[capacity];
for (size_t i = 0; i < count; ++i) {
items[i] = rightObject.items[i];
}
}
return *this;
}
Here is UListType.h:
#ifndef ULISTTYPE_H_INCLUDED
#define ULISTTYPE_H_INCLUDED
#include <iostream>
class UListType: public ListType {
public:
UListType(size_t=10);
bool insert(int);
bool erase(int);
bool find(int) const;
};
#endif // ULISTTYPE_H_INCLUDED
Here is UListType.cpp:
#include "ListType.h"
#include "UListType.h"
UListType::UListType (size_t c): ListType(c) {}
bool UListType::insert(int item) {
if (full()) {
int *newitems;
capacity *=2;
newitems = new int[capacity];
for (size_t i =0; i < count; ++i){
newitems[i] = items[i];
}
delete [] items;
items = newitems;
}
items[count++] = item;
return true;
}
bool UListType::erase(int item) {
bool result = false;
size_t i=0;
while ( i < count && items [i] != item) {
++i;
}
if (i < count) {
items[i] = items[-- count];
result = true;
}
return result;
}
bool UListType::find(int item) const {
size_t i = 0;
while (i < count && items [i] != item) {
++i;
}
return i < count;
}
Here is OListType.h:
#ifndef OLISTTYPE_H_INCLUDED
#define OLISTTYPE_H_INCLUDED
#include <iostream>
class OListType: public ListType {
public:
OListType(size_t=10);
bool insert(int);
bool erase(int);
bool find(int) const;
};
#endif // OLISTTYPE_H_INCLUDED
Here is OListType.cpp:
#include "ListType.h"
#include "OListType.h"
OListType::OListType(size_t c): ListType(c) {}
bool OListType::insert(int item) {
size_t i = count;
if (full()) {
int *newitems;
capacity *=2;
newitems = new int[capacity];
for(size_t j=0; j < count; ++j) {
newitems[j] = items[i];
}
delete [] items;
items = newitems;
}
while (i > 0 && items[i-1] > item){
items[count++] = item;
}
return true;
}
bool OListType::erase(int item) {
bool found=false;
size_t i=0, j= count-1, mid;
while (i <= j && !(found)){
mid = (i + j)/2;
if (item < items [mid])
j = mid - 1;
else if (item > items [mid])
i = mid + 1;
found = items [mid] == item;
}
if (found) {
for (i = mid; i < count - 1; ++i) {
items [i] = items [i +1];
}
--count;
}
return found;
}
bool OListType::find (int item) const {
bool found=false;
size_t i=0, j= count-1, mid;
while (i <= j && !(found)){
mid = (i + j)/2;
if (item < items [mid])
j = mid - 1;
else if (item > items [mid])
i = mid + 1;
found = items [mid] == item;
}
return found;
}
Here is Program01.cpp:
#include "ListType.h"
#include "UListType.h"
#include "OListType.h"
#include <iostream>
using namespace std;
int main() {
OListType list[5] = {165, 16, 118, 212, 104};
UListType ranlist[10] = {243, 300, 154, 153, 592, 124, 195, 217, 289, 405};
UListType UListAssignmentTest;
OListType OListAssignmentTest;
cout << "The Ordered List before operations:" << endl;
cout << list << endl << endl;
if(list.empty()) **<-- HERE BE THE ERROR**
cout << "The list is empty, therefore it is true.";
else
cout << "The list is full or partially full, therefore it is false";
cout << endl << endl;
if(list.full())
cout << "The list is full, therefore it is true.";
else
cout << "The list is partially full or empty, therefore it is false";
cout << endl << endl;
list.insert(25);
cout << endl << endl;
cout << "The Ordered list after Insert:" << endl;
cout << list << endl << endl;
list.find(25);
cout << endl << endl;
list.find(30);
cout << endl << endl;
list.erase(25);
cout << endl << endl;
cout << "The Ordered List after Erase:" << endl;
cout << list << endl << endl;
cout << "The Unordered List before operations:" << endl;
cout << ranlist << endl << endl;
if(ranlist.empty())
cout << "The list is empty, therefore it is true.";
else
cout << "The list is full or partially full, therefore it is false";
cout << endl << endl;
if(ranlist.full())
cout << "The list is full, therefore it is true.";
else
cout << "The list is partially full or empty, therefore it is false";
cout << endl << endl;
ranlist.insert(25);
cout << endl << endl;
cout << "The Unordered List after Insert:" << endl;
cout << ranlist << endl << endl;
ranlist.find(25);
cout << endl << endl;
ranlist.find(30);
cout << endl << endl;
ranlist.erase(25);
cout << endl << endl;
cout << "The Unordered List after Erase:" << endl;
cout << ranlist << endl << endl;
cout << "Testing Ordered List Assignment Operator" << endl;
OListAssignmentTest = list;
cout << OListAssignmentTest << endl << endl;
cout << "Testing Unordered List Assignment Operator" << endl;
UListAssignmentTest = ranlist;
cout << UListAssignmentTest << endl << endl
cout << "Testing Ordered List Copy Constructor" << endl;
OListType OListVariable = list;
cout << OListVariable << endl << endl;
cout << "Testing Unordered List Copy Constructor" << endl;
UListType UListVariable = ranlist;
cout << UListVariable << endl << endl;
cout << "Testing Erase All for OList" << endl;
list.eraseAll();
cout << "OList values now: " << list.empty() << endl << endl;
cout << "Testing Erase All for UList" << endl;
ranlist.eraseAll();
cout << endl << "UList values now: " << ranlist.empty() << endl;
return 0;
}
OListType list[5] = {165, 16, 118, 212, 104};
This line declares an array of 5 OListType types. This doesn't seem correct.
You want to declare one OLIstType and insert 5 values into it. If not, please clarify what that line is supposed to denote.
Here is probably what you are supposed to do:
OListType list;
list.insert(165);
list.insert(16); // etc...
I'm currently working on an assignment for school that says I should create a Queue. It seems to be working. The only problem is that there is an unexpected char at the beginning of my Queue. I use class CQueue to push and pop values from the queue. It is essential that I use this class instead of something like std::queue or deque.
class CQueue
{
private:
char *bottom_;
char *top_;
int size_;
public:
CQueue(int n = 20){
bottom_ = new char[n];
top_ = bottom_;
size_ = n;
}
void push(char c){
*top_ = c;
top_++;
}
int num_items() {
return (top_ - bottom_ );
}
char pop(){
bottom_++;
return *bottom_;
}
void print(){
cout << "Queue currently holds " << num_items() << " items: " ;
for (char *element=top_; element > bottom_; element--) {
cout << " " << *element;
}
cout << "\n";
}
This is my main method:
int main(){
CQueue q(10);
q.push('s');q.push('t');q.push('a');q.push('c');q.push('k');
q.print();
cout << "Popped value is: " << q.pop() << "\n";
q.print();
q.push('!');
q.push('?');
cout << "Popped value is: " << q.pop() << "\n";
q.print();
while (!q.empty()) q.pop();
if (q.num_items() != 0) {
cout << "Error: Stack is corrupt!\n";
}
q.print();
cout << "End of program reached\n"<< endl;
return 0;
When I run this code the queue gets filled but *bottom_ is replaced with a '=' symbol. This is my output:
Queue currently holds 5 items: ═ k c a t
Popped value is: t
Queue currently holds 4 items: ═ k c a
Popped value is: a
Queue currently holds 5 items: ═ ? ! k c
Queue currently holds 0 items:
End of program reached
I've been banging my head over this one for a while now so I hope that maybe you can shed some light on this problem!
As your push() is defined, *top_ is NOT in queue. It is one element after the end of queue. Therefore, you should define your print() to iterate from top_ - 1.
Also as #stellarossa mentioned, you should return the character pointed by bottom_ before increment. That is,
char pop() { return *(bottom_++); }
char pop(){
bottom_++;
return *bottom_;
}
you're incrementing your pointer and then returning the value. it should be the other way around.
Are you using an array or linked list?
Keep it simple and use an array with a count variable.
#include <iostream>
using namespace std;
class CQueue
{
private:
char * q;
int size_;
int count;
public:
CQueue(int n = 20){
q = new char[n];
size_ = n;
count = 0;
}
void push(char c){
assert(count != size);
q[count] = c;
count++;
}
int num_items() {
return count;
}
char pop() {
assert(count != 0);
char ret = q[count-1];
count--;
return ret;
}
void print(){
cout << "Queue currently holds " << num_items() << " items: " ;
for (int i = 0; i < count; i++) {
cout << " " << q[i];
}
cout << "\n";
}
At least two bugs my friend.
1) The print() method starts printing *top which is 1 past the last member. Should be:
for (char *element=top_-1; element >= bottom_; element--) {
cout << " " << *element;
}
2) The pop() method is wrong:
should be:
char pop(){
return (top_ > bottom_) ? *top_-- : 0;
}
everything i have read says this should be easy and that you just add these three lines
typedef double* DoublePtr;
DoublePtr p;
p = new double [10]
but where do i add this code? Everything i have tried just breaks my program what am I missing? I tried a set function to set the value of max size but it didn't work either
does anyone know how to do this?
#include<iostream>
using namespace std;
const int MAX_SIZE = 50;
class ListDynamic
{
public:
ListDynamic();
bool full();
int getSize();
void addValue(double value);
double getValue(int index);
double getLast();
void deleteLast();
friend ostream& operator <<(ostream& out, const ListDynamic& thisList);
private:
double listValues[MAX_SIZE];
int size;
};
int main()
{
double value;
ListDynamic l;
cout << "size of List " << l.getSize() << endl;
cout << "New size of List " << l.getSize() << endl;
cout << "First Value: " << l.getValue(0) << endl;
cout << "Last Value: " << l.getLast() << endl;
cout << "deleting last value from list" << endl;
l.deleteLast();
cout << "new list size " << l.getSize() << endl;
cout << "the list now contains: " << endl << l << endl;
system("pause");
return 0;
}
ListDynamic::ListDynamic()
{
size = 0;
}
bool ListDynamic::full()
{
return (size == MAX_SIZE);
}
int ListDynamic::getSize()
{
return size;
}
void ListDynamic::addValue(double value)
{
if (size < MAX_SIZE)
{
listValues[size] = value;
size++;
}
else
cout << "\n\n*** Error in ListDynamic Class: Attempting to add value past max limit.";
}
double ListDynamic::getValue(int index)
{
if (index < size)
return listValues[index];
else
cout << "\n\n*** Error in ListDynamic Class: Attempting to retrieve value past current size.";
}
double ListDynamic::getLast()
{
if (size > 0)
return getValue(size - 1);
else
cout << "\n\n*** Error in ListDynamic Class: Call to getLast in Empty List.";
}
void ListDynamic::deleteLast()
{
if (size > 0)
size--;
else
cout << "\n\n*** Error in ListDynamic Class: Call to deleteLast in Empty List.";
}
ostream& operator <<(ostream& out, const ListDynamic& thisList)
{
for (int i = 0; i < thisList.size; i++)
out << thisList.listValues[i] << endl;
return out;
}
You need to change listValues to a double*
double* listValues;
And when you add a value greater than the size, you'll need to reallocate the array your array and copy the elements of the former array to the new one. For example:
void ListDynamic::addValue(double value)
{
if (full())
{
double* temp = new double[size];
std::copy(listValues, listValues + size, temp);
delete[] listValues;
listValues = new double[size + 1];
std::copy(temp, temp + size, listValues);
listValues[size] = value;
delete[] temp;
} else
{
listValues[size++] = value;
}
}