-
Notifications
You must be signed in to change notification settings - Fork 0
Optimal sorting Kalsina Yana #5
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
yaprogrammer18-yanchi
wants to merge
15
commits into
main
Choose a base branch
from
optimisated_sort_branch
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
15 commits
Select commit
Hold shift + click to select a range
13900b9
Add all files from hw about optimal sorting
yaprogrammer18-yanchi 8150c18
Remove some silly things from files
yaprogrammer18-yanchi dd020ea
Remove mistakes
yaprogrammer18-yanchi 219ddcc
Changed README
yaprogrammer18-yanchi ade98ca
Change 'massive' into 'array' in some files
yaprogrammer18-yanchi 70fba14
Change list into array in sort.h and sort.c
yaprogrammer18-yanchi dc8deb2
used clang-format to main.c
yaprogrammer18-yanchi ab13a47
Fix some syntactic mistakes
yaprogrammer18-yanchi 97ee39c
Remove one useless line
yaprogrammer18-yanchi eb6413f
Removed one empty line
yaprogrammer18-yanchi cf60c92
Update sort.s, use clang-format to main.c and sort.c
yaprogrammer18-yanchi bde99cc
Remove empty line
yaprogrammer18-yanchi fe3ecb7
Add cmake and clang-format config
yaprogrammer18-yanchi 281c073
Formatted files
yaprogrammer18-yanchi 45dd2dd
Merge branch 'main' into optimisated_sort_branch
yaprogrammer18-yanchi 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 |
|---|---|---|
|
|
@@ -241,4 +241,4 @@ WhitespaceSensitiveMacros: | |
| - CF_SWIFT_NAME | ||
| - NS_SWIFT_NAME | ||
| - PP_STRINGIZE | ||
| - STRINGIZE | ||
| - STRINGIZE | ||
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
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 @@ | ||
| add_library(sort sort.c) | ||
| add_executable(main main.c) | ||
| target_link_libraries(main PRIVATE sort) |
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,7 @@ | ||
| Инструкция по сборке | ||
|
|
||
| gcc -Wall -Wextra -pedantic -S -O2 sort.c -o sort.s | ||
|
|
||
| gcc -Wall -Wextra -pedantic main.c -c | ||
|
|
||
| gcc -Wall -Wextra -pedantic main.o sort.s -o main |
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,31 @@ | ||
| #include "sort.h" | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| int main() | ||
| { | ||
| int* arrayWithNumbers = calloc(100, sizeof(int)); | ||
| int length = 0; | ||
| char nextSymbol = 0; | ||
| while (nextSymbol != '\n') { | ||
| int inputNumber = 0; | ||
| int input = scanf("%d", &inputNumber); | ||
| // scanf успешно прочитал введенное число | ||
| if (input == 1) { | ||
| // добавляем число в список | ||
| arrayWithNumbers[length++] = inputNumber; | ||
| } else { | ||
| return 1; | ||
| } | ||
| // читаем символ, который был введен дальше | ||
| nextSymbol = getchar(); | ||
| if (nextSymbol == '\n') { | ||
| break; | ||
| } | ||
| } | ||
| printf("%d\n", sort(arrayWithNumbers, length)); | ||
| return 0; | ||
| } | ||
|
|
||
| // пример: ввод 4 3 2 1 | ||
| // должно вернуть : 4, так как каждая цифра изменила свою позицию | ||
WoWaster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,29 @@ | ||
| #include "sort.h" | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| int sort(int* array, int length) | ||
| { | ||
| // c помощью этого списка будем считать элементы, изменившие свою позицию | ||
| int* unsortedArray = calloc(length, sizeof(int)); | ||
| memcpy(unsortedArray, array, sizeof(int) * length); | ||
| // сортировка пузырьком | ||
| for (int i = 0; i < length; i++) { | ||
| for (int j = 0; j < length - 1 - i; j++) { | ||
| if (array[j] > array[j + 1]) { | ||
| int tmp = array[j]; | ||
| array[j] = array[j + 1]; | ||
| array[j + 1] = tmp; | ||
| } | ||
| } | ||
| } | ||
| int count = 0; | ||
| // смотрим какие элементы изменили свою позицию | ||
| for (int k = 0; k < length; k++) { | ||
| if (array[k] != unsortedArray[k]) { | ||
| ++count; | ||
| } | ||
| } | ||
| free(unsortedArray); | ||
| return count; | ||
| } |
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,7 @@ | ||
| #pragma once | ||
|
|
||
| // функция сортировки | ||
WoWaster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // функция принимает указатель на первый эллемент массива и длину массива | ||
| // возвращает кол-во элементов, изменивших свою позицию | ||
| // сортировка реализуется пузырьковым методом | ||
| int sort(int* array, int length); | ||
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,107 @@ | ||
| .file "sort.c" | ||
| .text | ||
| .p2align 4 | ||
| .globl sort | ||
| .type sort, @function | ||
| sort: | ||
| .LFB11: | ||
| .cfi_startproc | ||
| pushq %r12 | ||
| .cfi_def_cfa_offset 16 | ||
| .cfi_offset 12, -16 | ||
| movslq %esi, %r12 | ||
| movl $4, %esi | ||
| pushq %rbp | ||
| .cfi_def_cfa_offset 24 | ||
| .cfi_offset 6, -24 | ||
| movq %rdi, %rbp | ||
| movq %r12, %rdi | ||
| pushq %rbx | ||
| .cfi_def_cfa_offset 32 | ||
| .cfi_offset 3, -32 | ||
| movq %r12, %rbx | ||
| salq $2, %r12 | ||
| call calloc@PLT | ||
| movq %r12, %rdx | ||
| movq %rbp, %rsi | ||
| movq %rax, %rdi | ||
| call memcpy@PLT | ||
| movq %rax, %r8 | ||
| testl %ebx, %ebx | ||
| jle .L9 | ||
| leal -1(%rbx), %edi | ||
| leaq -4(%rbp,%r12), %rsi | ||
| .p2align 4 | ||
| .p2align 3 | ||
| .L3: | ||
| movq %rbp, %rax | ||
| testl %edi, %edi | ||
| jle .L7 | ||
| .p2align 6 | ||
| .p2align 4 | ||
| .p2align 3 | ||
| .L5: | ||
| movq (%rax), %xmm0 | ||
| pshufd $0xe5, %xmm0, %xmm1 | ||
| movd %xmm0, %ecx | ||
| movd %xmm1, %edx | ||
| cmpl %edx, %ecx | ||
| jle .L4 | ||
| pshufd $225, %xmm0, %xmm0 | ||
| movq %xmm0, (%rax) | ||
| .L4: | ||
| addq $4, %rax | ||
| cmpq %rsi, %rax | ||
| jne .L5 | ||
| .L7: | ||
| subl $1, %edi | ||
| cmpq %rbp, %rsi | ||
| je .L10 | ||
| subq $4, %rsi | ||
| jmp .L3 | ||
| .p2align 4,,10 | ||
| .p2align 3 | ||
| .L10: | ||
| xorl %eax, %eax | ||
| xorl %ebx, %ebx | ||
| .p2align 5 | ||
| .p2align 4 | ||
| .p2align 3 | ||
| .L6: | ||
| movl (%r8,%rax), %edi | ||
| cmpl %edi, 0(%rbp,%rax) | ||
| je .L8 | ||
| addl $1, %ebx | ||
| .L8: | ||
| addq $4, %rax | ||
| cmpq %rax, %r12 | ||
| jne .L6 | ||
| movq %r8, %rdi | ||
| call free@PLT | ||
| movl %ebx, %eax | ||
| popq %rbx | ||
| .cfi_remember_state | ||
| .cfi_def_cfa_offset 24 | ||
| popq %rbp | ||
| .cfi_def_cfa_offset 16 | ||
| popq %r12 | ||
| .cfi_def_cfa_offset 8 | ||
| ret | ||
| .L9: | ||
| .cfi_restore_state | ||
| xorl %ebx, %ebx | ||
| movq %r8, %rdi | ||
| call free@PLT | ||
| movl %ebx, %eax | ||
| popq %rbx | ||
| .cfi_def_cfa_offset 24 | ||
| popq %rbp | ||
| .cfi_def_cfa_offset 16 | ||
| popq %r12 | ||
| .cfi_def_cfa_offset 8 | ||
| ret | ||
| .cfi_endproc | ||
| .LFE11: | ||
| .size sort, .-sort | ||
| .ident "GCC: (GNU) 15.2.1 20250813" | ||
| .section .note.GNU-stack,"",@progbits |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.