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 | |
download | cpp-ca080c19f1f3f8e3c23a207d936d03fd5f247d12.tar.gz cpp-ca080c19f1f3f8e3c23a207d936d03fd5f247d12.tar.bz2 cpp-ca080c19f1f3f8e3c23a207d936d03fd5f247d12.zip |
init new cpp project
-rw-r--r-- | .gitignore | 13 | ||||
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rwxr-xr-x | build.sh | 5 | ||||
-rw-r--r-- | src/main.cpp | 71 |
4 files changed, 98 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9c50bf --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps +CMakeUserPresets.json +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..20cad24 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.5) +project(joecpp) +add_executable(joecpp src/main.cpp) +set(OUTPUT_DEBUG "build/debug") +set(OUTPUT_REL "build/release") +# Output directory for libraries in Debug configuration +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}) +# Output directory for libraries in Release configuration +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/${OUTPUT_REL}) diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..90fcd53 --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +cd ./build +cmake .. +make +cd ../ 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; +} |