-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (67 loc) · 1.91 KB
/
Copy pathmain.cpp
File metadata and controls
79 lines (67 loc) · 1.91 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2026 CrimsonSeraph(ltyy.leoyu@gmail.com)
// SPDX-License-Identifier: MIT
#include "application/Polynomial.h"
#include "container/FixedVector.hpp"
#include "container/SinglyLinkedList.hpp"
#include <iostream>
#include <string>
void test_FixVector() {
FixedVector<std::string> vec(2);
vec.push_back("Hello");
vec.push_back("world! ");
std::cout << "vec.length(): " << vec.length() << std::endl;
vec.reserve(10);
vec.push_back("C++");
vec.push_back("is");
vec.push_back("awesome!");
std::cout << "vec.capacity(): " << vec.capacity() << std::endl;
vec.pop_back();
std::cout << "vec.length() after pop_back: " << vec.length() << std::endl;
vec.push_back("dificult! ");
vec.shrink_to_fit();
std::cout << "vec.capacity() after shrink_to_fit: " << vec.capacity()
<< std::endl;
for (const auto &s : vec) {
std::cout << s << " ";
}
std::cout << std::endl;
}
void test_SinglyLinkedList() {
SinglyLinkedList<int> list;
list.push_front(10);
list.push_front(20);
list.push_front(30);
std::cout << "Initial linked list: ";
for (const auto &val : list) {
std::cout << val << " ";
}
std::cout << std::endl; // 输出 30 20 10
list.insert_after(1, 99);
std::cout << "The linked list after insertion: ";
for (auto it = list.begin(); it != list.end(); ++it) {
std::cout << *it << " ";
}
std::cout << std::endl;
list.erase_after(2);
std::cout << "The list after deletion: ";
for (auto it = list.begin(); it != list.end(); ++it) {
std::cout << *it << " ";
}
std::cout << std::endl;
}
void test_Polynomial() {
Polynomial p;
p.insert_term(3, 2);
p.insert_term(2, 1);
p.insert_term(-1, 0);
std::cout << p.to_string() << std::endl;
std::cout << p.evaluate(2) << std::endl;
}
int main() {
// test_FixVector();
// std::cout << std::endl;
// test_SinglyLinkedList();
// std::cout << std::endl;
test_Polynomial();
return 0;
}