60 519
Assignments Done
98,2%
Successfully Done
In April 2018

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
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions