-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.cpp
More file actions
32 lines (29 loc) · 864 Bytes
/
Copy pathremove.cpp
File metadata and controls
32 lines (29 loc) · 864 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
/* TODO: write a function that takes an integer and a list, and removes
* the first occurrence of the integer, if found. Return value should be
* whether or not removal happened. */
#include <iostream>
using std::cout;
using std::cin;
/* NOTE: the node structure, as well as some utility functions used in
* main() are in list-utils.h which we include here. */
#include "list-utils.h"
bool remove(node*& L, int x)
{
/* TODO: write me */
return false; /* just so it compiles... */
}
int main()
{
/* NOTE: some test code for you is given below. It reads integers
* from stdin and tries to remove them from a hard-coded list. */
node* L = buildlist({1,3,5,7,9,11,13});
printlist(L);
int x;
while (cin >> x) {
printf("%i was %sremoved\n",x,remove(L,x)?"":"not ");
printf("new list contains:\n");
printlist(L);
}
return 0;
}
// vim:foldlevel=2