diff options
author | steven@devbox <steven@devbox.local> | 2025-05-09 22:53:11 +0000 |
---|---|---|
committer | steven@devbox <steven@devbox.local> | 2025-05-09 22:53:11 +0000 |
commit | ca080c19f1f3f8e3c23a207d936d03fd5f247d12 (patch) | |
tree | a9a39f2f7f1828a46a637764b12b8aeaac653792 /src/main.cpp | |
download | cpp-ca080c19f1f3f8e3c23a207d936d03fd5f247d12.tar.gz cpp-ca080c19f1f3f8e3c23a207d936d03fd5f247d12.tar.bz2 cpp-ca080c19f1f3f8e3c23a207d936d03fd5f247d12.zip |
init new cpp project
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..c5720bd --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,71 @@ +#include <iostream> +static int NUMITEMS = 30; +static int NULPTR = -1; +static std::string DATA[] = { + "Joe Australia", "Mark Carney", "Geert Wilders", "Mark Rutte", + "Donald J. Trump", "Xi Jinping", "Adolf Hitler"}; +class Node { +public: + std::string value; + int next; +}; +class LinkedList { +public: + int root; + int free; + Node *src; + void show() { + int i = root; + while (i != NULPTR) { + std::cout << "[" << i << "] " << src[i].value << " -> " << src[i].next + << std::endl; + i = src[i].next; + } + }; + void insert(std::string element) { + src[free].value = element; + int next = src[free].next; + src[free].next = root; + root = free; + free = next; + } + bool find(std::string element) { + int i = root; + while (i != NULPTR) { + if (src[i].value == element) { + return true; + } + i = src[i].next; + } + return false; + } +}; +int main() { + std::cout << "hello cpp" << std::endl; + int x = 0; + LinkedList l; + l.root = NULPTR; + l.free = 0; + Node nodes[NUMITEMS]; + for (int i = 0; i < NUMITEMS; i++) { + Node n; + n.value = "X"; + n.next = i + 1; + nodes[i] = n; + } + nodes[NUMITEMS - 1].next = NULPTR; // set last ptr + l.src = nodes; + for (const std::string &elem : DATA) { + l.insert(elem); + } + l.show(); + bool f1 = l.find("Xi"); + bool f2 = l.find("Steven"); + if (f1) { + std::printf("Found Xi\n"); + } + if (f2) { + std::printf("Found Steven\n"); + } + return 0; +} |