| | |
Need help with program segments
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 365
Reputation:
Solved Threads: 0
I need help with the programming segments below, so I can study for them...I showed my effort on trying to do them. However, I don't believe they are right. If someone can assist me with this, I will definitely appreciate it.
1. Determine if a word is a palindrome or not using queues
2. Return the last item of a queue leaving the queue unchanged
3. Replace every occurence of every (e) in a queue with an (x)
4. Give the sum of the 1st 3 elements in a queue leaving the queue unchanged
5. Reverse the elements in a queue
6. Exchange the front 2 elements of a queue
1. Determine if a word is a palindrome or not using queues
C++ Syntax (Toggle Plain Text)
q.addQueue(v); for (int i = q.front(); i < q.front(); i--) { for (int j = q.back(); i<q.back(); i++ { if ( q.front() == q.back() ) { cout<<"It is a palindrome"<<endl; } else { cout<<"It is not a palindrome"<<endl; } } }
2. Return the last item of a queue leaving the queue unchanged
C++ Syntax (Toggle Plain Text)
if (!p.QueueIsEmpty() ) { p.deleteQueue(v); } p.addQueue(v); cout<<v;
3. Replace every occurence of every (e) in a queue with an (x)
C++ Syntax (Toggle Plain Text)
if (!s.QueueIsEmpty) { for (int i=q.front(); i<q.front(); i--) { for (int j=q.back(); i<q.back(); i++) { if (q.front() == 'e') || (q.back() == 'e') { q.addQueue(x); } } }
4. Give the sum of the 1st 3 elements in a queue leaving the queue unchanged
C++ Syntax (Toggle Plain Text)
if (q.QueueIsEmpty()) { for (i = q.front(); i<q.front()-3; i--) { q.DeleteQueue(v) s.AddQueue(v) sum+=val; } for (int i =0; i<3; i++) { s.DeleteQueue(v); q.AddQueue(v); } else { cout<<"It is empty"<<endl; } cout<<"Sum is "<<sum;
5. Reverse the elements in a queue
C++ Syntax (Toggle Plain Text)
while (!s.QueueIsEmpty()) { p.DeleteQueue(v); } p.AddQueue(v); cout<<v<<" ";
6. Exchange the front 2 elements of a queue
C++ Syntax (Toggle Plain Text)
p.DeleteQueue(v); p.DeleteQueue(e); p.AddQueue(v); p.AddQueue(e);
-7
#2 22 Days Ago
We don't have the definition of your queue class so can't really tell if some of those are right or wrong.
2. Probably wrong. You are not supposed to delete the item from the queue. Just retrieve it. There is probably another way to get the item out of the queue without deleting it.
3. Definitely wrong. Just think a minute about what you have done with those loops. You first initialize variable i to be q.front() and then test to see if i is less and q.front() ??? Most likely should be this?
4. Similar answer as given for #2, above.
5 & 6. I have no idea since I don't know the definition of the queue class.
2. Probably wrong. You are not supposed to delete the item from the queue. Just retrieve it. There is probably another way to get the item out of the queue without deleting it.
3. Definitely wrong. Just think a minute about what you have done with those loops. You first initialize variable i to be q.front() and then test to see if i is less and q.front() ??? Most likely should be this?
for(int i = q.front(); i < q.back(); i++) What I don't know if what kind of data is in the queue. Is it a queue of strings (most likely answer considering the question), a queue of ints or what??4. Similar answer as given for #2, above.
5 & 6. I have no idea since I don't know the definition of the queue class.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2008
Posts: 365
Reputation:
Solved Threads: 0
0
#3 22 Days Ago
I am not using a queue class for these program segments. I apologize for any confusion. They are just programming segments made up to help me understand how to do them. On my test tomorrow, I have to write program segments "similar" to those that I put, and I just wanted to make sure I am prepared. They are basically just used for practice, I guess like pseudo code. Sorry for any confusion
An example of a program segment that I did that were correct:
Swap top 2 elements in a stack
Duplicate top element in a stack
Print the elements in the stack from top to bottom
An example of a program segment that I did that were correct:
Swap top 2 elements in a stack
C++ Syntax (Toggle Plain Text)
s.pop(v); s.pop(e); s.push(v); s.push(e);
Duplicate top element in a stack
C++ Syntax (Toggle Plain Text)
s.pop(v); s.push(v); s.push(v);
Print the elements in the stack from top to bottom
C++ Syntax (Toggle Plain Text)
while (!s.isempty()) { s.pop(v); cout<<v; }
Last edited by NinjaLink; 22 Days Ago at 3:09 pm.
![]() |
Similar Threads
- Popups and problem loading desktop (Viruses, Spyware and other Nasties)
- HJT Report/IE 6 SP2 Popups (Viruses, Spyware and other Nasties)
- IE Hijack Problem (Viruses, Spyware and other Nasties)
- hotoffers popup/homepage plz help (Viruses, Spyware and other Nasties)
- Need help!! getting rid of hotoffers.info (Viruses, Spyware and other Nasties)
- Hotoffers.info virus (Viruses, Spyware and other Nasties)
- hotoffers.info hijacker like everyone else... (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Solving quadratics from input file
- Next Thread: C++ and saveFileDialog
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






