Merge array.

i am stuck at
int main
. I dont how to create an array that will store in Queue and merge them. But I got the function and head files fine but thta int main (or test drive)

can someone show me

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
// Implementation file for the IntQueue class
#include <iostream>
#include "IntQueue.h"
using namespace std;

//***************************************************************
// This constructor creates an empty queue of a specified size. *
//***************************************************************

IntQueue::IntQueue(int s)
{
    queueArray = new int[s];
    queueSize = s;
    front = -1;
    rear = -1;
    numItems = 0;
}

//***************************************************************
// Copy constructor                                             *
//***************************************************************

IntQueue::IntQueue(const IntQueue &obj)
{
    // Allocate the queue array.
    queueArray = new int[obj.queueSize];
    
    // Copy the other object's attributes.
    queueSize = obj.queueSize;
    front = obj.front;
    rear = obj.rear;
    numItems = obj.numItems;
    
    // Copy the other object's queue array.
    for (int count = 0; count < obj.queueSize; count++)
        queueArray[count] = obj.queueArray[count];
}

//***************************************************************
// Destructor                                                   *
//***************************************************************
IntQueue::~IntQueue()
{
    delete [] queueArray;
}

//***************************************************************
// Function enqueue inserts a value at the rear of the queue.   *
//***************************************************************

void IntQueue::enqueue(int num)
{
    if (isFull())
        cout << "The queue is full.\n";
    else
    {
        // Calculate the new rear position
        rear = (rear + 1) % queueSize;
        // Insert new item
        queueArray[rear] = num;
        // Update item count
        numItems++;
    }
}

//***************************************************************
// Function dequeue removes the value at the front of the queue *
// and copies t into num.                                       *
//***************************************************************

void IntQueue::dequeue(int &num)
{
    if (isEmpty())
        cout << "The queue is empty.\n";
    else
    {
        // Move front
        front = (front + 1) % queueSize;
        // Retrieve the front item
        num = queueArray[front];
        // Update item count
        numItems--;
    }
}

//***************************************************************
// isEmpty returns true if the queue is empty, otherwise false. *
//***************************************************************

bool IntQueue::isEmpty() const
{
    bool status;
    if (numItems)
        status = false;
    else
        status = true;
    return status;
}

//***************************************************************
// isFull returns true if the queue is full, otherwise false.   *
//***************************************************************

bool IntQueue::isFull() const
{
    bool status;
    if (numItems < queueSize)
        status = false;
    else
        status = true;
    return status;
}

//*****************************************************************
// clear sets the front and rear indices, and sets numItems to 0. *
//***************************************************************** 




Head
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
// Specification file for the IntQueue class
#ifndef INTQUEUE_H
#define INTQUEUE_H

class IntQueue
{
private:
    int *queueArray;  // Points to the queue array
    int queueSize;    // The queue size
    int front;        // Subscript of the queue front
    int rear;         // Subscript of the queue rear
    int numItems;     // Number of items in the queue
public:
    // Constructor
    IntQueue(int);
    
    // Copy constructor
    IntQueue(const IntQueue &);
    
    // Destructor
    ~IntQueue();
    
    // Queue operations
    void enqueue(int);
    void dequeue(int &);
    bool isEmpty() const;
    bool isFull() const;
    void clear();
    
  

};


#endif 
Show you what?
Here is a link that should be helpful.
This is an example of how to merge an array:

http://www.cplusplus.com/forum/beginner/105600/
Topic archived. No new replies allowed.