C++ source code

hello,

i have problems to understand the following source code. It would be very nice when you could write to each line what Funktion it has. Thank you very much :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream> // for using cout
#include <list> // for using lists
using namespace std; // for std functions
typedef list<int>INTLIST;
void display(list<int>);
int main()
{
int i;
list<int>list1;
INTLIST list2;
// Filling the list with random numbers
for(i=0;i<4;i++)
{
list1.push_back(rand()%10);
list2.push_back(rand()%10);
}
display(list1); // Display the list
display(list2);
// Putting first element to the end as well
list1.push_back(list1.front());
list1.reverse(); // Reverse list
list1.sort(); // Sort list
list1.merge(list2); // Merge two lists
list1.sort(); // Remove multiple entries #1
list1.unique(); // Remove multiple entries #2
return 0;
}
void display(list<int>my_list)
{
int i;
list<int>::const_iterator iterator;
iterator = my_list.begin();
while(iterator != my_list.end())
{
i = *iterator;
cout << i << endl;
++iterator;
}
}
Last edited on
Please edit your post and use code tags for all of your code - http://www.cplusplus.com/articles/jEywvCM9/

All explanations regarding the list are here, including examples - http://www.cplusplus.com/reference/list/list/

As for the iterator part - https://www.youtube.com/watch?v=5bLNPFlEfqM

You can google using namespace std; and typedef ^^
Last edited on
Thank you for the very helpful link. I sadly cant find an explanation for "void display(list<int>);" and "void display(list<int>my_list)". Could you explain me what funktion they have?
The function they have is literally being a function.

void display(list<int>);

This is called a function prototype - https://en.wikipedia.org/wiki/Function_prototype

void display(list<int>my_list) This is the function itself - http://www.cplusplus.com/doc/tutorial/functions/

Again, please edit your post and use code tags for your code, Ive helped you out, the least you can do is listen :)
Topic archived. No new replies allowed.