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
7 changes: 7 additions & 0 deletions test(3)/queueWithStack/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>
#include "queue.h"
#include "stack.h"

int main(void) {
Queue* queue = createQueue();
}
33 changes: 33 additions & 0 deletions test(3)/queueWithStack/queue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "queue.h"
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"

struct Queue {
Stack* firstStack;
Stack* secondStack;
};

int enqueue(Queue* queue, int value) {
push(queue->firstStack, value);
}

int dequeue(Queue* queue) {
if (isEmpty(queue->secondStack)) {
int temp = pop(queue->firstStack);
while (temp != NULL) {
push(queue->firstStack);
temp = pop(queue->firstStack);
}
}
pop(queue->secondStack);
}

void deleteQueue(Queue* queue) {
while (!isEmpty(queue->firstStack) && !isEmpty(queue->secondStack)) {
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И саму queue надо ещё удалить


Queue* createQueue() {
return (Queue*)calloc(1, sizeof(Queue));
}
9 changes: 9 additions & 0 deletions test(3)/queueWithStack/queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

typedef struct Queue Queue;

int enqueue(Queue* queue, int value);

int dequeue(Queue* queue);

Queue* createQueue();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleteQueue тоже надо было вынести в заголовочный файл, и нужны комментарии

31 changes: 31 additions & 0 deletions test(3)/queueWithStack/queueWithStack.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.11.35222.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "queueWithStack", "queueWithStack.vcxproj", "{FF8D44EF-A49E-4736-B7C5-6D0B2644C723}"
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
{FF8D44EF-A49E-4736-B7C5-6D0B2644C723}.Debug|x64.ActiveCfg = Debug|x64
{FF8D44EF-A49E-4736-B7C5-6D0B2644C723}.Debug|x64.Build.0 = Debug|x64
{FF8D44EF-A49E-4736-B7C5-6D0B2644C723}.Debug|x86.ActiveCfg = Debug|Win32
{FF8D44EF-A49E-4736-B7C5-6D0B2644C723}.Debug|x86.Build.0 = Debug|Win32
{FF8D44EF-A49E-4736-B7C5-6D0B2644C723}.Release|x64.ActiveCfg = Release|x64
{FF8D44EF-A49E-4736-B7C5-6D0B2644C723}.Release|x64.Build.0 = Release|x64
{FF8D44EF-A49E-4736-B7C5-6D0B2644C723}.Release|x86.ActiveCfg = Release|Win32
{FF8D44EF-A49E-4736-B7C5-6D0B2644C723}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {675BC94F-C0BB-469D-AF9E-DCD653A1AEFA}
EndGlobalSection
EndGlobal
142 changes: 142 additions & 0 deletions test(3)/queueWithStack/queueWithStack.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{ff8d44ef-a49e-4736-b7c5-6d0b2644c723}</ProjectGuid>
<RootNamespace>queueWithStack</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.c" />
<ClCompile Include="queue.c" />
<ClCompile Include="stack.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="queue.h" />
<ClInclude Include="stack.h" />
<ClInclude Include="testStack.h" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testStack.h есть, а самих тестов нет

</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
43 changes: 43 additions & 0 deletions test(3)/queueWithStack/stack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include "stack.h"

typedef struct StackElement {
int value;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут внезапно табуляция вместо пробелов для отступа

struct StackElement* next;
} StackElement;

typedef struct Stack {
StackElement* head;
} Stack;

void push(Stack* stack, int value) {
StackElement* element = malloc(sizeof(StackElement));
if (element == NULL) {
return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хорошо, что тут есть хоть какой-то контроль ошибок, но плохо, что вызывающий никак не может узнать, удался push или нет.

}
element->value = value;
element->next = stack->head;
stack->head = element;
}

int pop(Stack* stack) {
if (stack->head == NULL) {
return 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут тоже, 1 может быть вполне корректным значением

}
StackElement* tmp = stack->head;
int value = tmp->value;
stack->head = stack->head->next;
free(tmp);
return value;
}

Stack* createStack() {
return (Stack*)calloc(1, sizeof(Stack));
}

bool isEmpty(Stack* stack) {
return stack->head == NULL;
}
16 changes: 16 additions & 0 deletions test(3)/queueWithStack/stack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <stdbool.h>

typedef struct Stack Stack;

Stack* createStack();

//function adds an item to the stack

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//function adds an item to the stack
// function adds an item to the stack

void push(Stack* stack, int value);

//function removes an item from the stack
int pop(Stack* stack);

//function checks if the stack is empty
bool isEmpty(Stack* stack);
15 changes: 15 additions & 0 deletions test(3)/queueWithStack/testStack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <stdbool.h>

//the function creates a stack and checks that it is not equal to NULL
bool testCreateStack();

//function tests adding an item to the stack
bool testPush();

//function tests deletion of an item from the stack
bool testPop();

//function tests to see if the stack is empty
bool testIsEmpty();