-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (38 loc) · 1.1 KB
/
main.cpp
File metadata and controls
46 lines (38 loc) · 1.1 KB
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
40
41
42
43
44
45
46
#include <iostream>
#include "LinkedBag.h"
int main() {
// Create and populate first bag
LinkedBag<int> bag1;
bag1.add(10);
bag1.add(20);
bag1.add(30);
// Test assignment operator
LinkedBag<int> bag2;
bag2.add(999); // Give it different data first
bag2 = bag1; // Assignment operator called here
// Verify bag2 has bag1's contents
std::cout << "bag2 contents after assignment:" << std::endl;
std::vector<int> items = bag2.toVector();
for (int item : items) {
std::cout << item << " ";
}
std::cout << std::endl;
// Test that it's a deep copy (modify bag1, bag2 shouldn't change)
bag1.add(40);
bag1.clear();
std::cout << "bag2 after modifying bag1:" << std::endl;
items = bag2.toVector();
for (int item : items) {
std::cout << item << " ";
}
std::cout << std::endl;
// Test self-assignment
bag2 = bag2;
std::cout << "bag2 after self-assignment:" << std::endl;
items = bag2.toVector();
for (int item : items) {
std::cout << item << " ";
}
std::cout << std::endl;
return 0;
}