Thread View: att.lang.c++
2 messages
2 total messages
Started by Joseph M Suprenant
Sun, 02 Apr 2000 00:00
help on dynamic q array
Author: Joseph M Suprenant
Date: Sun, 02 Apr 2000 00:00
Date: Sun, 02 Apr 2000 00:00
44 lines
1424 bytes
1424 bytes
My question is this: I have a qlass and in it I am tring to implemet a
dynamic array Q
My trouble comes when i have to double the size of the dynamic array.
It
just does not get work corectly here is my code:
void Qclass::Double ()
{
int* temp;
int i=0;
int item;
temp=new int[Qlength*2-1];
int tempHead;
int tempTail;
tempHead=head;
tempTail=tail;
while(!IsEmpty())
{
DeQ(item);
temp[i]=item;
i++;
}
delete[] que;
que=temp;
head=tempHead;
tail=tempTail;
Qlength=Qlength*2-1;
}
..////Deq looks like this
void Qclass::DeQ (int& item)
{
head=(head+1)%Qlength;
item=que[head];
}
Could some kind soul give me some insight on this?
thanks
joe
Re: help on dynamic q array
Author: js
Date: Wed, 05 Apr 2000 00:00
Date: Wed, 05 Apr 2000 00:00
52 lines
1671 bytes
1671 bytes
Unless you need to do this for a class assignment, I'd use a stl vector.
Joseph M Suprenant <laclac@global2000.net> wrote in message
news:38E70A6F.EB97579F@global2000.net...
> My question is this: I have a qlass and in it I am tring to implemet a
> dynamic array Q
> My trouble comes when i have to double the size of the dynamic array.
> It
> just does not get work corectly here is my code:
>
> void Qclass::Double ()
> {
>
> int* temp;
> int i=0;
> int item;
> temp=new int[Qlength*2-1];
> int tempHead;
> int tempTail;
> tempHead=head;
> tempTail=tail;
>
>
> while(!IsEmpty())
> {
> DeQ(item);
> temp[i]=item;
> i++;
> }
>
> delete[] que;
> que=temp;
> head=tempHead;
> tail=tempTail;
> Qlength=Qlength*2-1;
>
> }
> ..////Deq looks like this
> void Qclass::DeQ (int& item)
> {
>
> head=(head+1)%Qlength;
> item=que[head];
> }
>
> Could some kind soul give me some insight on this?
> thanks
> joe
>
>
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads