Skip to content

Commit ea57e8c

Browse files
committed
WIP
1 parent 7f4416b commit ea57e8c

14 files changed

+210
-356
lines changed

.gitignore

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,128 @@ __pycache__
1717

1818
# Visual Studio
1919
/.vs/
20+
21+
### C++ ###
22+
# Prerequisites
23+
*.d
24+
25+
# Compiled Object files
26+
*.slo
27+
*.lo
28+
*.o
29+
*.obj
30+
31+
# Precompiled Headers
32+
*.gch
33+
*.pch
34+
35+
# Compiled Dynamic libraries
36+
*.so
37+
*.dylib
38+
*.dll
39+
40+
# Fortran module files
41+
*.mod
42+
*.smod
43+
44+
# Compiled Static libraries
45+
*.lai
46+
*.la
47+
*.a
48+
*.lib
49+
50+
# Executables
51+
*.exe
52+
*.out
53+
*.app
54+
55+
### CMake ###
56+
CMakeLists.txt.user
57+
CMakeCache.txt
58+
CMakeFiles
59+
CMakeScripts
60+
Testing
61+
Makefile
62+
cmake_install.cmake
63+
install_manifest.txt
64+
compile_commands.json
65+
CTestTestfile.cmake
66+
_deps
67+
68+
### CMake Patch ###
69+
# External projects
70+
*-prefix/
71+
72+
### Linux ###
73+
*~
74+
75+
# temporary files which can be created if a process still has a handle open of a deleted file
76+
.fuse_hidden*
77+
78+
# KDE directory preferences
79+
.directory
80+
81+
# Linux trash folder which might appear on any partition or disk
82+
.Trash-*
83+
84+
# .nfs files are created when an open file is removed but is still being accessed
85+
.nfs*
86+
87+
### macOS ###
88+
# General
89+
.DS_Store
90+
.AppleDouble
91+
.LSOverride
92+
93+
# Icon must end with two \r
94+
Icon
95+
96+
97+
# Thumbnails
98+
._*
99+
100+
# Files that might appear in the root of a volume
101+
.DocumentRevisions-V100
102+
.fseventsd
103+
.Spotlight-V100
104+
.TemporaryItems
105+
.Trashes
106+
.VolumeIcon.icns
107+
.com.apple.timemachine.donotpresent
108+
109+
# Directories potentially created on remote AFP share
110+
.AppleDB
111+
.AppleDesktop
112+
Network Trash Folder
113+
Temporary Items
114+
.apdisk
115+
116+
### macOS Patch ###
117+
# iCloud generated files
118+
*.icloud
119+
120+
### Windows ###
121+
# Windows thumbnail cache files
122+
Thumbs.db
123+
Thumbs.db:encryptable
124+
ehthumbs.db
125+
ehthumbs_vista.db
126+
127+
# Dump file
128+
*.stackdump
129+
130+
# Folder config file
131+
[Dd]esktop.ini
132+
133+
# Recycle Bin used on file shares
134+
$RECYCLE.BIN/
135+
136+
# Windows Installer files
137+
*.cab
138+
*.msi
139+
*.msix
140+
*.msm
141+
*.msp
142+
143+
# Windows shortcuts
144+
*.lnk

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cmake_minimum_required(VERSION 3.24)
2+
23
project(
34
cpp_algorithms
45
LANGUAGES C CXX
@@ -10,9 +11,9 @@ find_library(MATH_LIBRARY m)
1011

1112
set(CMAKE_CXX_STANDARD 17)
1213
set(CMAKE_CXX_STANDARD_REQUIRED ON)
14+
include_directories(./include)
1315

14-
add_executable(cpp_algorithms main.cpp)
15-
add_subdirectory(leetcode)
16+
add_subdirectory(arrays)
1617

1718
cmake_policy(SET CMP0054 NEW)
1819
cmake_policy(SET CMP0057 NEW)

arrays/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_executable(array array.cpp)

arrays/array.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "../utils/common.hpp"
2+
3+
int randomAccess(const int *nums, int size) {
4+
int randomIndex = rand() % size;
5+
int randomNum = nums[randomIndex];
6+
return randomNum;
7+
}
8+
9+
int main() {
10+
int size = 5;
11+
int *arr = new int[size];
12+
13+
cout << "arr = ";
14+
printArray(arr, size);
15+
16+
int *nums = new int[size]{1, 3, 2, 5, 4};
17+
cout << "nums = ";
18+
printArray(nums, size);
19+
20+
int randomNum = randomAccess(nums, size);
21+
cout << "Get a random element from nums: " << randomNum << endl;
22+
}

leetcode/CMakeLists.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

leetcode/preorder_traversal.cpp

Lines changed: 0 additions & 92 deletions
This file was deleted.

leetcode/tree.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

leetcode/two_sum.cpp

Lines changed: 0 additions & 48 deletions
This file was deleted.

leetcode/zigzag_conversion.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)