Answer to Question #21390 in C++ for Alaa

Question #21390
Implement a function DisplayEven(...) that displays only the even elements inserted by the user. i.e.: element number 0, element number 2, etc.using double linked list
1
Expert's answer
2013-01-28T10:33:57-0500
#include <conio.h>
#include <list>
#include <string>
#include <iostream>

using namespace std;

void DisplayEven(list<string>& lst)
{
list<string>::iterator i = lst.begin();
for (int c = 0; c < lst.size(); c += 2)
{
cout << "Element " << c << ": " << *i << endl;
advance(i, 2);
}
}

void main()
{
list<string> lst;
string tmp;

cout << "Enter string values one by one or 'q' to stop:" << endl;
while (true)
{
getline(cin, tmp);
if (tmp == "q")
break;
lst.push_back(tmp);
}

cout << endl;
DisplayEven(lst);
_getch();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS