From 857a97c13021e664cdfbbdd1600c97941667827a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D0=B4=D0=B0=D1=88=D0=BE=D0=B2=20=D0=90=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=D0=B4=D0=B8=D0=B9?= Date: Sun, 19 Oct 2014 00:14:38 +0400 Subject: [PATCH 1/4] com --- .gitignore | 157 +++++++++++++++++++++++++++++ task1/sources/task/iface.h | 197 ++++++++++++++++++++++--------------- 2 files changed, 274 insertions(+), 80 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..22741f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,157 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets +!packages/*/build/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc +*.opensdf + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + + +#LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac desktop service store files +.DS_Store diff --git a/task1/sources/task/iface.h b/task1/sources/task/iface.h index e90797f..08d6369 100644 --- a/task1/sources/task/iface.h +++ b/task1/sources/task/iface.h @@ -1,80 +1,117 @@ -/** - * @file: task/iface.h - * Interface of a programming task - */ -#include "../Utils/utils_iface.h" - -/* namespaces import */ -using namespace Utils; - -//Debug assert with diagnostic info -#if !defined(DLIST_ASSERTXD) -# define DLIST_ASSERTXD(cond, what) ASSERT_XD(cond, "DList", what) -#endif - -// Simple debug assert -#if !defined(DLIST_ASSERTD) -# define DLIST_ASSERTD(cond) ASSERT_XD(cond, "DList", "") -#endif - -/** - * Namespace for the programming task - */ -namespace Task -{ - // - // Doubly connected list - // - template class DList - { - public: - // - // List unit - // - class Unit - { - public: - // ---- This interface is part of the task --- - Unit *next(); // Get the next unit in list - Unit *prev(); // Get the previous unit in list - T& val(); // Get the reference to the unit's value - private: - // ---- Implementation routines ---- - - - // ---- Data involved in the implementation ---- - - }; - - // ---- Public interface of DList ---- - DList(); //< Constructor - ~DList();//< Destructor - - void push_front (const T& val); // Insert one unit with given value at front - void pop_front(); // Remove one unit at front of the list - void push_back (const T& val); // Insert one unit with given value to back - void pop_back(); // Remove one unit from the back of the list - Unit* insert (Unit* u, const T& val); // Insert one unit before the given one - - Unit* first(); // Get first unit - Unit* last(); // Get last unit - - Unit* erase (Unit* u); // Remove given unit from list, return next unit or null - void clear(); // Remove all units - bool empty(); // Check if list is empty. Returns true if empty, false otherwise - unsigned size(); // Get the number of units in the list - void reverse(); // Reverse the order of units in the list -private: - // ---- The internal implementation routines ---- - - // ---- The data involved in the implementation ---- - - }; - - bool uTest( UnitTest *utest_p); -}; - -// Since we have defined list as a template - we should implement the solution in a header -// But to keep interface clean we've separated the implementation into list_impl.h header -#include "list_impl.h" - +/** + * @file: task/iface.h + * Interface of a programming task + */ +#include "../Utils/utils_iface.h" + +/* namespaces import */ +using namespace Utils; + +//Debug assert with diagnostic info +#if !defined(DLIST_ASSERTXD) +# define DLIST_ASSERTXD(cond, what) ASSERT_XD(cond, "DList", what) +#endif + +// Simple debug assert +#if !defined(DLIST_ASSERTD) +# define DLIST_ASSERTD(cond) ASSERT_XD(cond, "DList", "") +#endif + +/** + * Namespace for the programming task + */ +namespace Task +{ + // + // Doubly connected list + // + template class DList + { + public: + // + // List unit + // + class Unit + { + public: + // ---- This interface is part of the task --- + Unit *next() // Get the next unit in list + { + return next; + } + Unit *prev() // Get the previous unit in list + { + return prev; + } + T& val() // Get the reference to the unit's value + { + return &value; + } + private: + // ---- Implementation routines ---- + T value; + Unit *next, *prev; + + + // + // ---- Data involved in the implementation ---- + + }; + + // ---- Public interface of DList ---- + DList(): head(NULL) , tail(NULL) , count(0) {}; //< Constructor + ~DList()//< Destructor + { + while (head) //Пока по адресу на начало списка что-то есть + { + tail = head->Next; //Резервная копия адреса следующего звена списка + delete head; //Очистка памяти от первого звена + head = tail; //Смена адреса начала на адрес следующего элемента + } + delete count; + } + + void push_front (const T& val); // Insert one unit with given value at front + void pop_front(); // Remove one unit at front of the list + void push_back (const T& val); // Insert one unit with given value to back + void pop_back(); // Remove one unit from the back of the list + Unit* insert (Unit* u, const T& val); // Insert one unit before the given one + + Unit* first() // Get first unit + { + return head; + } + Unit* last() // Get last unit + { + return tail; + } + + Unit* erase (Unit* u); // Remove given unit from list, return next unit or null + void clear(); // Remove all units + bool empty() // Check if list is empty. Returns true if empty, false otherwise + { + return count; + } + unsigned size() // Get the number of units in the list + { + return count; + } + void reverse(); // Reverse the order of units in the list +private: + // ---- The internal implementation routines ---- + int count; + Unit *val; + Unit *head; + Unit *tail; + // ---- The data involved in the implementation ---- + + }; + + + bool uTest( UnitTest *utest_p); +}; + +// Since we have defined list as a template - we should implement the solution in a header +// But to keep interface clean we've separated the implementation into list_impl.h header +#include "list_impl.h" + From 16f899d173d14c3df6ea83398d49a77c74286a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D0=B4=D0=B0=D1=88=D0=BE=D0=B2=20=D0=90=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=D0=B4=D0=B8=D0=B9?= Date: Sun, 19 Oct 2014 12:19:32 +0400 Subject: [PATCH 2/4] com2, no_reverse --- task1/sources/task/iface.h | 156 ++++++++++++++++++++++++++++++++++--- 1 file changed, 146 insertions(+), 10 deletions(-) diff --git a/task1/sources/task/iface.h b/task1/sources/task/iface.h index 08d6369..1ec3ea1 100644 --- a/task1/sources/task/iface.h +++ b/task1/sources/task/iface.h @@ -64,18 +64,103 @@ namespace Task { while (head) //Пока по адресу на начало списка что-то есть { - tail = head->Next; //Резервная копия адреса следующего звена списка + tail = head->next; //Резервная копия адреса следующего звена списка delete head; //Очистка памяти от первого звена head = tail; //Смена адреса начала на адрес следующего элемента } delete count; } - void push_front (const T& val); // Insert one unit with given value at front - void pop_front(); // Remove one unit at front of the list - void push_back (const T& val); // Insert one unit with given value to back - void pop_back(); // Remove one unit from the back of the list - Unit* insert (Unit* u, const T& val); // Insert one unit before the given one + void push_front (const T& val) // Insert one unit with given value at front + { + count++; + if (empty() != 0)) + { + Unit *node_to_add = new Unit(val); + node_to_add->next = head; + node_to_add->prev = 0; + node_to_add->value = val; + head->prev = node_to_add; + } + else + { + Unit *node_to_add = new Unit(val); + node_to_add->next = tail; + node_to_add->prev = tail->prev; + node_to_add->value = val; + + tail->prev->next = node_to_add; + tail->prev = node_to_add; + } + } + void pop_front() // Remove one unit at front of the list + { + count--; + cout << head->value; + if (val != NULL) // проверка корректности + { + val = head; + head = val->next; + delete(val); + head->prev = NULL; + val = head; + } + } + void push_back (const T& val) // Insert one unit with given value to back + { + count++; + if (empty() != 0)) + { + Unit *node_to_add = new Unit(val); + node_to_add->next = 0; + node_to_add->prev = tail; + node_to_add->value = val; + tail->next = node_to_add; + } + else + { + Unit *node_to_add = new Unit(val); + node_to_add->next = tail; + node_to_add->prev = tail->prev; + node_to_add->value = val; + + tail->prev->next = node_to_add; + tail->prev = node_to_add; + } + } + void pop_back() // Remove one unit from the back of the list + { + count--; + cout << tail->value; + val = tail; + if (val->next == NULL) // проверка корректности + { + val->prev->next = NULL; + delete(val); + val = head; + } + } + Unit* insert (Unit* u, const T& val) // Insert one unit before the given one + { + count++; + Unit *node_to_add = new Unit(val); + if (empty() == 0) + { + node_to_add->next = tail; + node_to_add->prev = tail->prev; + node_to_add->value = val; + tail->prev->next = node_to_add; + tail->prev = node_to_add; + } + else + { + node_to_add->next = u; + node_to_add->prev = u->prev; + node_to_add->value = val; + u->prev->next = node_to_add; + u->next->prev = node_to_add; + } + } Unit* first() // Get first unit { @@ -86,8 +171,56 @@ namespace Task return tail; } - Unit* erase (Unit* u); // Remove given unit from list, return next unit or null - void clear(); // Remove all units + Unit* erase (Unit* u) // Remove given unit from list, return next unit or null + { + count--; + Unit *ptr; // вспомогательный указатель + ptr = u->next; + if (u == head) + { + if (val != NULL) // проверка корректности + { + val = u; + head = val->next; + delete(val); + head->prev = 0; + val = head; + } + return ptr; + } + if (u == tail) + { + val = u; + if (val->next == NULL) // проверка корректности + { + val->prev->next = NULL; + delete(val); + val = head; + } + return ptr; + } + else + { + val = u; + val->prev->next = val->next->prev; + delete(val); + val = head; + return ptr; + } + + } + void clear() // Remove all units + { + while (head) // + { + tail = head->Next; // + delete head; // + head = tail; // + } + head = NULL; + tail = NULL; + count = 0; + } bool empty() // Check if list is empty. Returns true if empty, false otherwise { return count; @@ -96,11 +229,14 @@ namespace Task { return count; } - void reverse(); // Reverse the order of units in the list + void reverse() // Reverse the order of units in the list + { + + } private: // ---- The internal implementation routines ---- int count; - Unit *val; + Unit *val; //текущий элемент Unit *head; Unit *tail; // ---- The data involved in the implementation ---- From 887d2e7ee604e106ff1914228b75c9add3292057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D0=B4=D0=B0=D1=88=D0=BE=D0=B2=20=D0=90=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=D0=B4=D0=B8=D0=B9?= Date: Sun, 19 Oct 2014 12:32:40 +0400 Subject: [PATCH 3/4] com3,no_reverse --- task1/sources/task/iface.h | 108 ++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/task1/sources/task/iface.h b/task1/sources/task/iface.h index 1ec3ea1..1fb24e3 100644 --- a/task1/sources/task/iface.h +++ b/task1/sources/task/iface.h @@ -72,26 +72,26 @@ namespace Task } void push_front (const T& val) // Insert one unit with given value at front - { - count++; - if (empty() != 0)) - { - Unit *node_to_add = new Unit(val); - node_to_add->next = head; - node_to_add->prev = 0; - node_to_add->value = val; - head->prev = node_to_add; - } - else - { - Unit *node_to_add = new Unit(val); - node_to_add->next = tail; - node_to_add->prev = tail->prev; - node_to_add->value = val; - - tail->prev->next = node_to_add; - tail->prev = node_to_add; - } + { + count++; + if (empty() != 0)) + { + Unit *node_to_add = new Unit(val); + node_to_add->next = head; + node_to_add->prev = 0; + node_to_add->value = val; + head->prev = node_to_add; + } + else + { + Unit *node_to_add = new Unit(val); + node_to_add->next = tail; + node_to_add->prev = tail->prev; + node_to_add->value = val; + + tail->prev->next = node_to_add; + tail->prev = node_to_add; + } } void pop_front() // Remove one unit at front of the list { @@ -109,24 +109,24 @@ namespace Task void push_back (const T& val) // Insert one unit with given value to back { count++; - if (empty() != 0)) - { - Unit *node_to_add = new Unit(val); - node_to_add->next = 0; - node_to_add->prev = tail; - node_to_add->value = val; - tail->next = node_to_add; - } - else - { - Unit *node_to_add = new Unit(val); - node_to_add->next = tail; - node_to_add->prev = tail->prev; - node_to_add->value = val; - - tail->prev->next = node_to_add; - tail->prev = node_to_add; - } + if (empty() != 0)) + { + Unit *node_to_add = new Unit(val); + node_to_add->next = 0; + node_to_add->prev = tail; + node_to_add->value = val; + tail->next = node_to_add; + } + else + { + Unit *node_to_add = new Unit(val); + node_to_add->next = tail; + node_to_add->prev = tail->prev; + node_to_add->value = val; + + tail->prev->next = node_to_add; + tail->prev = node_to_add; + } } void pop_back() // Remove one unit from the back of the list { @@ -144,12 +144,12 @@ namespace Task { count++; Unit *node_to_add = new Unit(val); - if (empty() == 0) - { - node_to_add->next = tail; - node_to_add->prev = tail->prev; - node_to_add->value = val; - tail->prev->next = node_to_add; + if (empty() == 0) + { + node_to_add->next = tail; + node_to_add->prev = tail->prev; + node_to_add->value = val; + tail->prev->next = node_to_add; tail->prev = node_to_add; } else @@ -209,16 +209,16 @@ namespace Task } } - void clear() // Remove all units - { - while (head) // - { - tail = head->Next; // - delete head; // - head = tail; // - } - head = NULL; - tail = NULL; + void clear() // Remove all units + { + while (head) // + { + tail = head->Next; // + delete head; // + head = tail; // + } + head = NULL; + tail = NULL; count = 0; } bool empty() // Check if list is empty. Returns true if empty, false otherwise From 153a092262bc3a1650bab8795aa24d2897740dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D0=B4=D0=B0=D1=88=D0=BE=D0=B2=20=D0=90=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=D0=B4=D0=B8=D0=B9?= Date: Sun, 19 Oct 2014 15:32:25 +0400 Subject: [PATCH 4/4] com4 --- task1/sources/task/iface.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/task1/sources/task/iface.h b/task1/sources/task/iface.h index 1fb24e3..434a663 100644 --- a/task1/sources/task/iface.h +++ b/task1/sources/task/iface.h @@ -88,7 +88,6 @@ namespace Task node_to_add->next = tail; node_to_add->prev = tail->prev; node_to_add->value = val; - tail->prev->next = node_to_add; tail->prev = node_to_add; } @@ -102,7 +101,7 @@ namespace Task val = head; head = val->next; delete(val); - head->prev = NULL; + head->prev = 0; val = head; } } @@ -231,7 +230,16 @@ namespace Task } void reverse() // Reverse the order of units in the list { - + val = head; + while( val->next != NULL) + { + tail->prev->next = NULL; + head->next = head; + head->prev = 0; + head = tail; + tail = tail->prev; + val = head->next; + } } private: // ---- The internal implementation routines ----