The first thing to do if you are "very weak in C++" is to stop being weak in C++.
To learn the basics of C++, start here:
http://www.cplusplus.com/doc/tutorial/
Secondly, wow. Does your teacher want you to implement a queue on top of an array? That's unwieldy, to say the least.
A queue is a FIFO (First In First Out) data structure.
This basically means that you always add elements to the end, and always remove elements from the front.
You cannot insert or delete elements from whatever position you want.
So I'd suggest renaming the
insert() and
delete() functions to
push() and
pop().
(By the way, if you're supposed to use C++ and still your teacher suggested using a "delete" as a function name... never mind.)
Queue operation example:
push(2)
show(): [2]
push(10)
show(): [2 10]
push(3)
push(3)
push(4)
show(): [2 10 3 3 4]
pop()
show(): [10 3 3 4]
pop()
pop()
show(): [3 4]
|
So how to use an array to mimic the above behavior?
Let's do it simply by using a fixed-size array like
int arr[100];
.
This means our queue will be able to hold a maximum of 100 numbers.
Then we need to remember the real size of the queue.
Every time we use
push(), we increase the size.
Every time we use
pop(), we decrease the size.
The trick is in the
pop() function. Not only must we decrease the size, but also shift the array one position left, overwriting the first element.