The issue I am having is not all elements are pushing to my final list from my stacks. Hopefully the code and explanations will give enough detail. If there are any questions feel free to ask. Any help would be really appreciated.
Global function that takes my Male stack and Female Stack. It pushes them alternatively to my LHS (left hand side of a "table") and RHS (right hand side of a "table".
BuildFinal(MaleStack, FemaleStack);//Call function above. With the below //functions I push from my LHS and RHS into the final seating list.
while (!RHS.empty())
{
RHSsorted.push(RHS.top());
RHS.pop();
}
while (!LHS.empty())
{
FinalSeating.push_back(LHS.top());
LHS.pop();
}
FinalSeating.push_back(Salesman("Guest Speaker", 0, male));
while (!RHSsorted.empty())
{
FinalSeating.push_back(RHSsorted.top());
RHSsorted.pop();
}
Here is an example of some of the output, but it does this as well even if the original list has more Lady Salesman. Also both male and females are generated randomly.
Sorting
Salesman Name: Lady Salesman Sex: Female Sales Amount: $133
Salesman Name: Gentleman Salesman Sex: Male Sales Amount: $305
Salesman Name: Lady Salesman Sex: Female Sales Amount: $395
Salesman Name: Gentleman Salesman Sex: Male Sales Amount: $423
Salesman Name: Gentleman Salesman Sex: Male Sales Amount: $428
Salesman Name: Gentleman Salesman Sex: Male Sales Amount: $566
Salesman Name: Gentleman Salesman Sex: Male Sales Amount: $626
Salesman Name: Gentleman Salesman Sex: Male Sales Amount: $644
Salesman Name: Gentleman Salesman Sex: Male Sales Amount: $695
Done Sorting
Press any key to continue . . .
Sepearating Lists
Done Seperating Lists
Bulding Final List
Printing Final List
Press any key to continue . . .
Salesman Name: Lady Salesman Sex: Female Sales Amount: $133
Salesman Name: Gentleman Salesman Sex: Male Sales Amount: $695
Salesman Name: Guest Speaker Sex: Male Sales Amount: $0
Salesman Name: Lady Salesman Sex: Female Sales Amount: $395
Salesman Name: Gentleman Salesman Sex: Male Sales Amount: $644
Press any key to continue . . .
The while will run only as long as both MS and FS are not empty. Once either becomes empty, the loop will exit. I suspect you want it to run as long as either stack has elements.
Also, see if you can make your conditionals simpler. It's difficult to tell what the code is supposed to be doing.
Yeah as I looked through the code I thought the initial condition for the while loop was causing that. But I can't seem to think of what I can do for the condition. For the rest of the code, I am pushing the gentleman and female salesman alternatively to the LHS and RHS. Afterwards pushing both the LHS and RHS to the final list as well as a "Guest Speaker". Viewing the table would be seen as Salesman with the largest sales amount next to the Guest speaker. But it starts with the a gentleman to the left and a lady to the right. And from there is alternates. I hope that helps any extra input or example would be great.