C++ question...

dssanton

Junior Member
Apr 24, 2000
7
0
0
I have about 90% of a project done but I am running into a wall now. I wrote a class that is a normal queue. It has normal functions like insert, delete, ...but the one function I am having problems writing is purge. It just needs to be a simple function that looks through all the elements in an array (a for loop) and removes any duplicates.

Any ideas???

Thanks,

Dan
 

slipperyslope

Banned
Oct 10, 1999
1,622
0
0
well the easy and most INEFFICIENT way to do it would be to use two for loop.....use the outside loop variable to compare to the loop variable used on the inside loop.

Basically compare each array space to every other.

That will get the job done.

Jim
 

BCYL

Diamond Member
Jun 7, 2000
7,803
0
71
Does the ordering of the queue needs to be maintained? If not, you can simply create a new empty queue, copy the elements in the original queue over to the new queue one by one... before you insert to your new queue, check if that element is already there... When you have went through the original queue, just delete it and use the newly created queue...
 

dssanton

Junior Member
Apr 24, 2000
7
0
0
Yeah, the order has to be maintained. It is a dynamic queue so if the queue is full, it gets one bigger. I have that part down. Just this stupid purge function. I'll try the two for loops in the morning.

Thanks and keep the ideas coming.

Dans87
 

BCYL

Diamond Member
Jun 7, 2000
7,803
0
71
Actually you can maintain the order too if you create a new queue and add the elements in. Just go thru the original queue in order and your newly created queue will maintain the order also...