-
Notifications
You must be signed in to change notification settings - Fork 0
HW4 CMake for Optimal sort #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DolzhenkoAlexa
wants to merge
16
commits into
main
Choose a base branch
from
HW4_OptimalSort_Dolzhenko
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1a7ad30
Create main.c
DolzhenkoAlexa 0fb8979
Create sort.c
DolzhenkoAlexa 7c2289b
Create CMakeLists.txt
DolzhenkoAlexa ef5bed3
Fixed CMakeLists.txt
DolzhenkoAlexa ba1cb83
Update sort.c
DolzhenkoAlexa d218a63
Update sort.c
DolzhenkoAlexa d092b8d
Update main.c + new names
DolzhenkoAlexa 04b5d07
Update CMakeLists.txt with custom commands
DolzhenkoAlexa 4369012
Create sort.h
DolzhenkoAlexa 93c3599
Create README.md
DolzhenkoAlexa 8cbbfaf
Fix README.md
DolzhenkoAlexa 7c96274
New logic for sort.c
DolzhenkoAlexa 097ce33
Update main.c
DolzhenkoAlexa bf5ae69
Removed sort.s from CMakeLists.txt
DolzhenkoAlexa 38c2fbe
Add easy version of CMakeLists.txt
DolzhenkoAlexa 31df553
Update README.md
DolzhenkoAlexa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| cmake_minimum_required(VERSION 4.0) | ||
| project(hw4_optimalSort C) | ||
|
|
||
| set(CMAKE_C_STANDARD 17) | ||
|
|
||
| add_executable(hw4_optimalSort | ||
| main.c | ||
| sort.c | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Код на С для домашней работы "Оптимальная" сортировка. | ||
| Здесь четыре файла - один main с чтением вводимых чисел, и во втором сортировка пузырьком (для вводимых данных в количестве 100 штук О(n^2) будет быстрым) и заголовочный файл sort.h, а также CMake для сборки без ассемблера | ||
|
|
||
| # Запуск: (с созданием ассемлерного файла с оптимизацией О2) | ||
| gcc -S -O2 sort.c -o sort.s && gcc -c main.c -o main.o && gcc -c sort.s -o sort.o && gcc main.o sort.o -o sorterWithASM | ||
| ./sorterWithASM | ||
| 10 1 9 -1 0 6 #Вводим до 100 чисел и затем завершаем ввод сочетанием Ctrl+D | ||
|
|
||
| # Запуск через CMake: | ||
| cmake -B build && cmake --build build | ||
| ./build/hw4_optimalSort | ||
| 10 1 9 -1 0 6 #Вводим до 100 чисел и затем завершаем ввод сочетанием Ctrl+D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include <stdio.h> | ||
| #include "sort.h" | ||
|
|
||
| int main() | ||
| { | ||
| int array[100]; | ||
| int count = 0; | ||
|
|
||
| while (count < 100 && scanf("%d", &array[count]) == 1) { | ||
| count++; | ||
| } | ||
|
|
||
| int moved = sortArray(array, count); | ||
|
|
||
| for (int i = 0; i < count; i++) { | ||
| // Чтоб удобнее глазками считать колво перестановок | ||
| printf("%d ", array[i]); | ||
| } | ||
| printf("\n"); | ||
|
|
||
| printf("%d ", moved); | ||
| return moved; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include "sort.h" | ||
|
|
||
| int sortArray(int array[], int count) | ||
| { | ||
| int movedCount = 0; | ||
|
|
||
| // Копия массива | ||
| int original[100]; | ||
| for (int i = 0; i < count; i++) { | ||
| original[i] = array[i]; | ||
| } | ||
|
|
||
| for (int i = 0; i < count - 1; i++) { | ||
| int swapped = 0; | ||
| for (int j = 0; j < count - i - 1; j++) { | ||
| if (array[j] > array[j + 1]) { | ||
| int temp = array[j]; | ||
| array[j] = array[j + 1]; | ||
| array[j + 1] = temp; | ||
| swapped = 1; | ||
| } | ||
| } | ||
| if (!swapped) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < count; i++) { | ||
| if (array[i] != original[i]) { | ||
| movedCount++; | ||
| } | ||
| } | ||
|
|
||
| return movedCount; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #pragma once | ||
|
|
||
| int sortArray(int array[], int count); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Где-то у Вас ошибка. На вводе
1 8 2 15получается 1, а должно быть 2.