Skip to content

Commit

Permalink
Merge pull request #8 from viktorvorobev/pr-setup-cpp
Browse files Browse the repository at this point in the history
Setup simple C++ project
  • Loading branch information
viktorvorobev authored Jun 15, 2024
2 parents 928e08a + 6b9609b commit 2ecc6a2
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 2 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/cpp-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: C++ CI

on:
pull_request:
branches: [ master ]
paths:
- 'cpp/**'
push:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./cpp
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y \
build-essential \
cmake
- name: Create Build directory
run: mkdir -p build

- name: Configure CMake
run: cmake -S . -B build

- name: Build the Project
run: cmake --build build --config Release

- name: Dummy test
run: ./build/algo_practice
2 changes: 1 addition & 1 deletion .github/workflows/python-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run:
working-directory: ./py
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand Down
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Python gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -128,3 +130,53 @@ dmypy.json

# Pyre type checker
.pyre/

# C++ gitignore

# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# CMake stuff

CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Practice

[![Python CI](https://github.com/victorvorobev/algo_practice/actions/workflows/python-check.yaml/badge.svg?branch=master)](https://github.com/victorvorobev/algo_practice/actions/workflows/python-check.yaml)
[![Python CI](https://github.com/viktorvorobev/algo_practice/actions/workflows/python-check.yaml/badge.svg?branch=master)](https://github.com/viktorvorobev/algo_practice/actions/workflows/python-check.yaml)
[![C++ CI](https://github.com/viktorvorobev/algo_practice/actions/workflows/cpp-check.yaml/badge.svg?branch=master)](https://github.com/viktorvorobev/algo_practice/actions/workflows/cpp-check.yaml)
[![linkedin](https://img.shields.io/badge/LinkedIn-0077B5?&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/mr-viktor-vorobev/)
[![](https://img.shields.io/badge/My%20CV-00A98F?logo=googledrive&logoColor=white)](https://drive.google.com/file/d/1e45Z14JU7wt4H0zuaQfNd0Xz4Yu0q1h-/view?usp=share_link)

Expand Down
12 changes: 12 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.13.4)

project(algo_practice)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(${PROJECT_NAME} src/main.cpp)

target_include_directories(${PROJECT_NAME}
PUBLIC "${PROJECT_BINARY_DIR}" "include"
)
15 changes: 15 additions & 0 deletions cpp/include/search.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <vector>

template <typename T>
int linearSearch(std::vector<T> &list, T target)
{
for (int i = 0; i < list.size(); i++)
{
if (list[i] == target)
{
return i;
}
}

return -1;
}
19 changes: 19 additions & 0 deletions cpp/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <vector>
#include <iostream>

#include "search.h"

int main()
{
std::vector<int> data = {10, 20, 30, 40};
int key = 30;
int result = linearSearch(data, key);
if (result != -1)
{
std::cout << "Found at index: " << result << std::endl;
}
else
{
std::cout << "Failed to find element" << std::endl;
}
}

0 comments on commit 2ecc6a2

Please sign in to comment.