replaced solution of week 1 and 2, extern files added so there are no stream it snippets of code in it. added week 5 FileIO .c and .h file

This commit is contained in:
Remco
2016-03-30 21:34:00 +02:00
parent e46c3838ce
commit c2b96802ce
15 changed files with 43 additions and 2 deletions
+154
View File
@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" 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">
<ProjectGuid>{736EDFAE-09BD-418B-86F9-DA794D727516}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>CRKWeek1</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</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" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h" />
</ItemGroup>
</Project>
+307
View File
@@ -0,0 +1,307 @@
#include "main.h"
#include <stdio.h>
#include <string.h>
void main()
{
/*char string[100];
int result = strcpy(string, "test");
printf("result %d, string %s\n", result, string);
char s1[100];
strcpy(s1, "remco");
char s2[100];
strcpy(s2, "kenneth");
strCat(&s1, &s2);
printf("Nieuw string: %s\n", s1);*/
//gaat goed
/*
char s1[10];
strcpy(s1, "taart");
char s2[10];
strcpy(s2, "art");
printf("Result taart en art: %d\n", strend(s1, s2));
//gaat niet goed, niet hetzelfde
char s3[10];
strcpy(s3, "taart");
char s4[10];
strcpy(s4, "taa");
printf("Result taart en taa: %d\n", strend(s3, s4));
//gaat niet goed, niet s6 > s5
char s5[10];
strcpy(s5, "taart");
char s6[20];
strcpy(s6, "verjaardagstaart");
printf("Result taart en verjaardagstaart: %d\n", strend(s5, s6));
*/
//fahrenheit();
//celsius();
//char str[128];
//strcpy(str, "Hallo dit is een zin die best wel heel erg lang zou kunnen zijn voor c programming");
//reverse_string(str);
//char str[32];
//strcpy(str, "Test f ");
//printf("%s:\n", str);
//trim(str);
//printf("%s:\n", str);
char str1[32];
char str2[16];
strcpy(str1, "acccddddefghijk");
strcpy(str2, "bdcgij");
//remove_chars(str1, str2);
printf("Index of first same char: %d\n",first(str1, str2));
}
void strCat(char* a, char* b)
{
int i, j;
i = j = 0;
while (a[i] != '\0')
i++;
while((a[i++] = b[j++]) != '\0')
;
}
int strend(char s[], char t[])
{
int sls,slt;
sls = strlen(s);
slt = strlen(t);
if (slt > sls) {
return 0;
}
sls--;
for (int i = slt - 1; i >= 0; i--)
{
if (t[i] != s[sls]) {
return 0;
}
sls--;
}
return 1;
}
void fahrenheit(void)
{
float fahr, celsius;
int laagste, hoogste, interval;
laagste = 0;
hoogste = 300;
interval = 20;
fahr = laagste;
printf("\n F C\n");
printf("-----------\n");
while (fahr <= hoogste)
{
celsius = (5.0 / 9.0) * (fahr - 32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + interval;
}
}
void celsius(void)
{
float fahr, celsius;
int laagste, hoogste, interval;
laagste = 0;
hoogste = 150;
interval = 10;
celsius = laagste;
printf("\n C F\n");
printf("-----------\n");
while (celsius <= hoogste)
{
fahr = (celsius*1.8) + 32.0;
printf("%3.0f %6.1f\n", celsius, fahr);
celsius = celsius + interval;
}
}
void histogram_length(char * string)
{
int length = 0;
strcat(string, " ");
printf("%s\n", string);
for (; *string; string++)
{
if (*string != ' ' && *string != '\0')
{
length++;
}
else
{
for (int i = 0; i < length; i++)
printf("-");
printf("\n");
length = 0;
}
}
}
void histogram_freq(char * string)
{
int chfreq[128] = {0};
printf("%s\n", string);
for (; *string; string++)
{
if (*string == ' ')
continue;
int chid = *string - '0';
chfreq[chid]++;
}
for (int i = 0; i < 128; i++)
{
if (chfreq[i] != 0)
{
printf(" %c ", i + '0');
for (int p = 0; p < chfreq[i]; p++)
printf("-");
printf("\n");
}
}
}
void reverse_string(char * string)
{
int chars = strlen(string);
char *buffer = malloc(sizeof(char) * chars);
int t = chars - 1;
for (int i = t; i >= 0; i--)
{
buffer[chars - 1 - i] = string[i];
}
strncpy(string, buffer, chars);
printf("%s\n", string);
free(buffer);
}
void trim(char *str)
{
char *end;
if (*str == 0) // All spaces?
return;
// Trim trailing space
end = str + strlen(str) - 1;
while (end > str && isspace(*end)) end--;
// Write new null terminator
*(end + 1) = '\0';
str = end;
}
void remove_chars(char * str1, char * str2)
{
int chex[128] = { 0 };
for (; *str2; str2++)
{
if (*str2 == ' ')
continue;
int chid = *str2 - '0';
chex[chid] = 1;
}
int chars = strlen(str1);
int count = 0;
char *buffer = malloc(sizeof(char) * chars);
for (; *str1; str1++)
{
if (chex[*str1 - '0'] != 1)
{
printf("Char %c stays\n", *str1);
buffer[count] = *str1;
count++;
}
else
printf("Char %c removed\n", *str1);
}
str1[count] = '\0';
strncpy(str1, buffer, count);
printf("%s\n", str1);
free(buffer);
}
int first(char * str1, char * str2)
{
int chex[128] = { 0 };
for (; *str2; str2++)
{
if (*str2 == ' ')
continue;
int chid = *str2 - '0';
chex[chid] = 1;
}
int count = 0;
for (; *str1; str1++)
{
if (chex[*str1 - '0'] == 1)
{
return count;
}
count++;
}
return -1;
}
+11
View File
@@ -0,0 +1,11 @@
#pragma once
void fahrenheit(void);
void celsius(void);
void histogram_length(char *);
void histogram_freq(char *);
void reverse_string(char *);
void trim(char *);
void remove_chars(char *, char *);
int first(char *, char *);
void strCat(char* a, char* b);
int strend(char s[],char t[]);
+156
View File
@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" 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">
<ProjectGuid>{B1FF6384-6F00-4702-9915-6BAC8DC696EA}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>CRKWeek2</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</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" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="heap.c" />
<ClCompile Include="llist.c" />
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="heap.h" />
<ClInclude Include="llist.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="llist.c" />
<ClCompile Include="main.c" />
<ClCompile Include="heap.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="llist.h" />
<ClInclude Include="heap.h" />
</ItemGroup>
</Project>
+28
View File
@@ -0,0 +1,28 @@
# Voorbeeld Makefile
#
# @ Diederich Kroeske, 2011
#
CC = gcc
#CC = avr-gcc
TARGET = llexample
CFLAGS = -Wall -O2
all : $(TARGET)
llist.o : llist.c llist.h
echo $@
$(CC) -c llist.c $(CFLAGS)
main.o : main.c
$(CC) -c main.c $(CFLAGS)
$(TARGET): main.o llist.o
$(CC) main.o llist.o $(CFLAGS) -o $(TARGET)
clean :
rm -f $(TARGET) main.o llist.o
info :
@echo "$(CC) using $(CFLAGS)"
+29
View File
@@ -0,0 +1,29 @@
/*Dit is de C file om aan te tonen dat de heap verandert,
wanneer de double linked list wordt aangepast*/
#include "llist.h"
void check_heap(void)
{
add(12,0);//voeg 12 toe aan het einde
printf("Heapsize: %d\n",NutHeapAvailable());
add(13,0);//voeg 13 toe aan het einde
printf("Heapsize: %d\n",NutHeapAvailable());
remove(1);//de voorste verwijderen, dus integer 12
printf("Heapsize: %d\n",NutHeapAvailable());
add(11,1);//voeg 11 toe aan het begin
printf("Heapsize: %d\n",NutHeapAvailable());
add(14,1);//voeg 14 toe aan het begin
printf("Heapsize: %d\n",NutHeapAvailable());
add(15,0);//voeg 15 toe aan het begin
printf("Heapsize: %d\n",NutHeapAvailable());
removePos(2);//verwijder positie 1, dus integer 11
printf("Heapsize: %d\n",NutHeapAvailable());
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef HEAP_DEF
#define HEAP_DEF
void check_heap(void);
#endif
+230
View File
@@ -0,0 +1,230 @@
#include "stdlib.h"
#include "stdio.h"
#include "llist.h"
static struct node *pEnd = NULL;
static struct node *pStart = NULL;
void init()
{
printf("Running init...\n");
pEnd = NULL;
pStart = NULL;
}
/*
* Aan de voorkant invoegen
*/
int add(int data, int begin)
{
struct node *pn = (struct node*)malloc(sizeof(struct node));
if(NULL == pn)
{
printf("Out of memory ...\n");
}
else
{
if (NULL == pStart)
{
pn->data = data;
pn->previous = NULL;
pn->next = NULL;
pStart = pn;
pEnd = pn;
}
else if (begin)
{
pStart->previous = pn;
pn->data = data;
pn->next = pStart;
pn->previous = NULL;
pStart = pn;
}
else
{
pEnd->next = pn;
pn->data = data;
pn->previous = pEnd;
pn->next = NULL;
pEnd = pn;
}
}
return 1;
}
int addPos(int data, int positie)
{
struct node *pn = (struct node*)malloc(sizeof(struct node));
if (NULL == pn)
{
printf("Out of memory ...\n");
}
else
{
if (NULL == pStart)
{
add(data, '1');
}
else
{
if (positie < 0)
{
printf("Positie < 0 : %d ...\n", positie);
return 0;
}
int idx = 0;
struct node *p = pStart;
for (; NULL != p->next; p = p->next)
{
if (positie == idx)
{
pn->data = data;
pn->next = p;
pn->previous = p->previous;
p->previous->next = pn;
p->previous = pn;
return 1;
}
idx++;
}
printf("Positie > %d : %d ...\n", idx, positie);
free(pn);
return 0;
}
}
return 1;
}
void show()
{
printf("Showing data...\n");
struct node *p = pStart;
int nr = 0;
if (NULL == pStart)
{
printf("De lijst is leeg\n");
}
else
{
while (1)
{
printf("node nr: %d heeft data [%d]\n", nr++, p->data);
if (p->next == NULL)
break;
p = p->next;
}
}
}
void clear()
{
printf("Clearing data...\n");
struct node *p = pEnd;
struct node *prev = NULL;
for (; NULL != p->previous;)
{
prev = p->previous;
free(p);
p = prev;
}
pEnd = NULL;
pStart = NULL;
printf("De gehele lijst in gecleared!\n");
}
int length()
{
int idx = 0;
struct node *p = pStart;
for (; NULL != p->next; p = p->next)
{
idx++;
}
return idx;
}
int exists(int data)
{
int idx = 0;
struct node *p = pStart;
for (; NULL != p->next; p = p->next)
{
if (p->data == data)
{
return idx;
}
idx++;
}
return -1;
}
int remove(int begin)
{
struct node *p = NULL;
if (begin == 1)
{
p = pStart->next;
p->previous = NULL;
free(pStart);
pStart = p;
}
else
{
p = pEnd->previous;
p->next = NULL;
free(pEnd);
pEnd = p;
}
return 1;
}
int removePos(int positie)
{
int i;
if (positie == 0)
{
remove(1);
}
else if (positie == length())
{
remove(0);
}
else if (positie < length())
{
struct node *r = pStart; //the node you want to remove
/*looping till you got to the positie, and save the node*/
for (i = 0; i < (positie - 1); i++)
{
r = r->next;
}
r->previous->next = r->next;
r->next->previous = r->previous;
free(r);
}
return 1;
}
+21
View File
@@ -0,0 +1,21 @@
#ifndef LLIST_DEF
#define LLIST_DEF
struct node
{
int data;
struct node *next;
struct node *previous;
};
#endif
void init();
int add(int data, int begin);
int addPos(int data, int positie);
void show(void);
void clear(void);
int length(void);
int exists(int data);
int remove(int);
int removePos(int);
+56
View File
@@ -0,0 +1,56 @@
#include <stdio.h>
#include "llist.h"
int main()
{
int idx;
init();
printf("Adding data at end...\n");
for(idx = 0; idx < 10; idx++)
{
add(idx, '0');
}
show();
clear();
show();
printf("Adding data at begin and end...\n");
for (idx = 0; idx < 10; idx++)
{
if (idx % 2 == 0)
add(idx, 1);
else
add(idx, 0);
}
addPos(22, 5);
addPos(22, 40);
addPos(22, -10);
show();
printf("Length of list: %d\n", length());
printf("Position of 22 in list: %d\n", exists(22));
printf("Position of 40 in list: %d\n", exists(40));
remove(1);
removePos(3);
show();
clear();
printf("Done\n");
return 1;
}
+38
View File
@@ -0,0 +1,38 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "C-RK-Week1", "C-RK-Week1\C-RK-Week1.vcxproj", "{736EDFAE-09BD-418B-86F9-DA794D727516}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "C-RK-Week2", "C-RK-Week2\C-RK-Week2.vcxproj", "{B1FF6384-6F00-4702-9915-6BAC8DC696EA}"
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
{736EDFAE-09BD-418B-86F9-DA794D727516}.Debug|x64.ActiveCfg = Debug|x64
{736EDFAE-09BD-418B-86F9-DA794D727516}.Debug|x64.Build.0 = Debug|x64
{736EDFAE-09BD-418B-86F9-DA794D727516}.Debug|x86.ActiveCfg = Debug|Win32
{736EDFAE-09BD-418B-86F9-DA794D727516}.Debug|x86.Build.0 = Debug|Win32
{736EDFAE-09BD-418B-86F9-DA794D727516}.Release|x64.ActiveCfg = Release|x64
{736EDFAE-09BD-418B-86F9-DA794D727516}.Release|x64.Build.0 = Release|x64
{736EDFAE-09BD-418B-86F9-DA794D727516}.Release|x86.ActiveCfg = Release|Win32
{736EDFAE-09BD-418B-86F9-DA794D727516}.Release|x86.Build.0 = Release|Win32
{B1FF6384-6F00-4702-9915-6BAC8DC696EA}.Debug|x64.ActiveCfg = Debug|x64
{B1FF6384-6F00-4702-9915-6BAC8DC696EA}.Debug|x64.Build.0 = Debug|x64
{B1FF6384-6F00-4702-9915-6BAC8DC696EA}.Debug|x86.ActiveCfg = Debug|Win32
{B1FF6384-6F00-4702-9915-6BAC8DC696EA}.Debug|x86.Build.0 = Debug|Win32
{B1FF6384-6F00-4702-9915-6BAC8DC696EA}.Release|x64.ActiveCfg = Release|x64
{B1FF6384-6F00-4702-9915-6BAC8DC696EA}.Release|x64.Build.0 = Release|x64
{B1FF6384-6F00-4702-9915-6BAC8DC696EA}.Release|x86.ActiveCfg = Release|Win32
{B1FF6384-6F00-4702-9915-6BAC8DC696EA}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal