Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion HomeworksAccept/homework21.09/read.me

This file was deleted.

1 change: 0 additions & 1 deletion HomeworksAccept/homework28.09/read.me

This file was deleted.

1 change: 0 additions & 1 deletion HomeworksAccept/read.me

This file was deleted.

31 changes: 31 additions & 0 deletions sortedList/sortedList.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sortedList", "sortedList\sortedList.vcxproj", "{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Debug|x64.ActiveCfg = Debug|x64
{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Debug|x64.Build.0 = Debug|x64
{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Debug|x86.ActiveCfg = Debug|Win32
{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Debug|x86.Build.0 = Debug|Win32
{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Release|x64.ActiveCfg = Release|x64
{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Release|x64.Build.0 = Release|x64
{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Release|x86.ActiveCfg = Release|Win32
{C52FFB7D-40D3-4BB3-92B4-A6F3E0B708F9}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2314527A-D566-40BA-9919-A77EF21F134B}
EndGlobalSection
EndGlobal
121 changes: 121 additions & 0 deletions sortedList/sortedList/list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#include "list.h"
#include <stdbool.h>
#include <string.h>

typedef struct Node {
int value;
struct Node* next;
} Node;

struct List {
Node* head;
};

void print(List* list) {
Node* walker = list->head;
while (walker != NULL) {
printf("%d ", walker->value);
walker = walker->next;
}
printf("\n");
}

bool isEmpty(List* list) {
return list->head == NULL;
}

int insert(List* list, int value) {
Node* newNode = calloc(1, sizeof(Node));
if (newNode == NULL) {
return -1;
}
newNode->value = value;
Node* currentNode = list->head;

if (currentNode != NULL && currentNode->value >= value) {
newNode->next = currentNode;
list->head = newNode;
return 0;
}

while (currentNode != NULL) {
if (currentNode->next == NULL || currentNode->next->value >= value) {
break;
}
currentNode = currentNode->next;
}

if (currentNode == NULL) {
list->head = newNode;
return 0;
}
newNode->next = currentNode->next;
currentNode->next = newNode;
return 0;
}

void clearList(List** list) {
if ((*list)->head != NULL) {
while ((*list)->head->next != NULL) {
Node* walker = (*list)->head;
while (walker->next != NULL && walker->next->next != NULL) {
walker = walker->next;
}
free(walker->next);
walker->next = NULL;
}
free((*list)->head->next);
free((*list)->head);
}
*list = NULL;
}

int top(List* list) {
if (list->head == NULL) {
return -1;
}
return list->head->value;
}

int delete(List* list, int value) {
Node* currentNode = list->head;

if (isEmpty(list)) {
return -1;
}
if (currentNode->value == value) {
Node* temp = currentNode->next;
free(currentNode);
list->head = temp;
return 0;
}

while (currentNode != NULL) {
if (currentNode->next == NULL || currentNode->next->value == value) {
if (currentNode->next == NULL && currentNode->value != value) {
return -1;
}
break;
}
currentNode = currentNode->next;
}

if (currentNode == NULL) {
return -1;
}

if (currentNode->next != NULL) {
Node* temp = currentNode->next->next;
free(currentNode->next);
currentNode->next = temp;
return 0;
}

free(currentNode->next);
return 0;
}

List* createList(void) {
List* list = calloc(1, sizeof(List));
return list;
}
19 changes: 19 additions & 0 deletions sortedList/sortedList/list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include <stdbool.h>
#include <stdlib.h>

typedef struct List List;

int insert(List* list, int value);

void print(List* list);

int delete(List* list, int value);

bool isEmpty(List* list);

void clearList(List** list);

List* createList(void);

int top(List* list);
79 changes: 79 additions & 0 deletions sortedList/sortedList/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
#include <locale.h>
#include <stdbool.h>

int scanOne() {
int number = 0;
int checkScanf = scanf("%d", &number);

while (checkScanf != 1) {
while (getchar() != '\n') {
}

printf("%s", "������... ��������� ������������ ����� \n");
checkScanf = scanf("%d", &number);
}

return number;
}

bool talkWithUser(void) {
List* list = createList();
printf(" 0 � �����\n 1 � �������� �������� � ������������� ������\n 2 � ������� �������� �� ������\n 3 � ����������� ������\n");
int userComand = scanOne();
while (userComand != 0) {
if (userComand == 1) {
printf("������� ��������\n");
int value = scanOne();
if (insert(list, value) == -1) {
return false;
}
}
else if (userComand == 2) {
printf("������� ��������\n");
int number = scanOne();
if (delete(list, number) == -1) {
printf("���������, �� �� �������� �� �����!\n");
}
} else if (userComand == 3) {
print(list);
}
printf("������� ��������� �������\n");
userComand = scanOne();
}

clearList(&list);
return true;
}

bool tests() {
List* list = createList();
insert(list, 100);
if (top(list) != 100) {
clearList(&list);
return false;
}
delete(list, 100);
if (top(list) != -1) {
clearList(&list);
return false;
}
clearList(&list);
return true;
}

int main() {
setlocale(LC_ALL, "RUS");
if (tests()) {
printf("����� ������ �������\n");
} else {
printf("���-�� ������...\n");
return 0;
}
bool check = talkWithUser();
if (!check) {
printf("��������� ������...\n");
}
}
Loading