Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Needs Help with Stacks and Queues PLEASE!!!!!!!

Status
Not open for further replies.

staminch

Programmer
Nov 15, 2001
9
US
Hello,
I need to perform the following using stacks and queues. I would appreciate any help. thanks.
1. Create a file that holds first and last name. (lets say sta minch).
2. read the file.
3. creat a stack names s_name.
4. push all characters from first name into stack s_name.
5. create a queue named q_name.
6. Place all characters from last name into q_name.
7. Create 2 sets names set1_name and set2_name.
8. Take all charactets out of s_name, print them as a string, and insert them into the set set1_name.
9. Take all charactets out of q_name, print them as a string, and insert them into the set set2_name.
10. create the union, intersection, and difference of 2 sets, set1_name and set2_name, and print results as strings of characters.


 
Do you have to implement the stacks and queues yourself, or are you allowed to use the STL? What areas do you have problems with?
 
Yes, i must use stl. Im pretty much having trouble with the whole stack/ queue concept. I would apprciate any help.
 
The code below is not the one you asked , instead , I'm showing you how to use and STL template of a Stack. The Queue STL is similar . In case of doubts , ask me.


#include <stack>
using namespace std;

struct myType
{
char FirstName[20];
char LastName[20];
}
stack<myType> myStack;

void main(void)
{
struct myType myStruct,myStructAux;
strcpy(myStruct.FirstName,&quot;Write your first name&quot;);
strcpy(myStruct.LastName,&quot;Write your last name&quot;);
myStack.push(myStruct);
// if you want to see what's on the top ,use myStack.top
myStructAux = myStack.top();
printf(&quot;%s\n&quot;,myStructAux.FirstName);
//if you want to get something out of the stack , use
//pop
myStack.pop();
}
 
thanks, how would i read name file in the .cpp portion? Do i just write first and last names in .txt format, and read it in the .cpp file?

what must i add to this template to complete everything in my list? how do i do the queue part?
thanks for the responses.
 
Just bringing this up, because I still need help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top