-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-test.cpp
More file actions
36 lines (32 loc) · 769 Bytes
/
list-test.cpp
File metadata and controls
36 lines (32 loc) · 769 Bytes
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
#include <iostream>
using std::cin;
using std::cout;
struct node {
int data;
node* next;
};
int main(void)
{
/* read all integers from stdin into a list */
node* L = NULL;
int x;
while (cin >> x) {
/* do steps 1 -- 4 */
node* n = new node; /* step 1 */
n->data = x; /* step 2 */
n->next = L; /* step 3 */
L = n; /* step 4 */
}
node* p = L;
while (p != NULL) {
cout << p->data << " ";
p = p->next;
}
return 0;
/* TODO: make sure you understand all this! */
}
/* TODO: write another program, similar to the above, which reads all
* of stdin into a list *in the same order* (the above reverses the
* order). */
/* TODO: make sure you have understood the most recent additions to
* the ../whatstheoutput/ directory ({6,7}.cpp, I think). */