From ca080c19f1f3f8e3c23a207d936d03fd5f247d12 Mon Sep 17 00:00:00 2001 From: "steven@devbox" Date: Fri, 9 May 2025 22:53:11 +0000 Subject: init new cpp project --- .gitignore | 13 +++++++++++ CMakeLists.txt | 9 ++++++++ build.sh | 5 +++++ src/main.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100755 build.sh create mode 100644 src/main.cpp 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 +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; +} -- cgit