diff --git a/Arefev_DA/lab1/include/Function.h b/Arefev_DA/lab1/include/Function.h new file mode 100644 index 000000000..ba176dfca --- /dev/null +++ b/Arefev_DA/lab1/include/Function.h @@ -0,0 +1,21 @@ +#ifndef FUNCTION_H +#define FUNCTION_H +#include "TLink.h" +#include "TList.h" +#include "TStack.h" +#include +#include +#include +using namespace std; +class st +{ +public: + static string postfix_form(string); + static float calculations(string); + static string correct(string s); +private: + static int prioretet(char); + static map readvalue(const string&); +}; + +#endif diff --git a/Arefev_DA/lab1/include/TLink.h b/Arefev_DA/lab1/include/TLink.h new file mode 100644 index 000000000..f14ecfbc0 --- /dev/null +++ b/Arefev_DA/lab1/include/TLink.h @@ -0,0 +1,12 @@ +#ifndef TLINK_H +#define TLINK_H + +template +class TLink +{ +public: + T Key; + TLink*pNext; +}; + +#endif diff --git a/Arefev_DA/lab1/include/TList.h b/Arefev_DA/lab1/include/TList.h new file mode 100644 index 000000000..f7715e787 --- /dev/null +++ b/Arefev_DA/lab1/include/TList.h @@ -0,0 +1,172 @@ +#ifndef TLIST_H +#define TLIST_H +#include "TLink.h" +#include +using namespace std; + +template +class TList +{ +private: + TLink*root; +public: + TList(); + ~TList(); + TList(const TList& a); + void insert_start(T key); + void insert_end(T key); + void insert_before(T key, T keyNext); + void insert_after(T key, T keyprev); + TLink* Search(T key); + void Remove(T key); + TLink* Top()const; +}; +template +TList::TList() +{ + root = 0; +}; + +template +TList::~TList() +{ + TLink* node = root; + while (root != 0) + { + root = root->pNext; + delete node; + } +}; + +template +TList::TList(const TList& a) +{ + if (a.root == 0) return 0; + TLink*node = a.root; + root->Key = node->key; + root->pNext = 0; + node = node->pNext; + TLink*tmp = root; + while (root != 0) + { + tmp->pNext = new TLink; + tmp->pNext->pNext = 0; + tmp = tmp->pNext; + node = node->pNext; + } + +} + +template +void TList::insert_start(T key) +{ + TLink*n = new TLink; + n->Key = key; + n->pNext = root; + root = n; +}; + +template +void TList::insert_end(T key) +{ + if (root == 0) + { + root = new TLink; + root->key = key; + root->pNext = 0; + return; + } + while (root->pNext != 0) + { + root = root->pNext; + } + root->pNext = new TLink; + root->pNext->key = key; + root->pNext->pNext = 0; +}; + +template +void TList::insert_before(T key, T keyNext) +{ + if (root == 0) + return; + if (root->key == keyNext) + { + Add(key); + return; + } + TList*Nroot = root; + while ((Nroot->pNext != 0) && (Nroot->pNext->key != keyNext)) + Nroot = Nroot->pNext; + if (Nroot->pNext == 0) + { + throw "Error! There is no such key"; + } + TList*n = new Node; + n->key = key; + n->pNext = Nroot->pNext; + Nroot->pNext = n; +}; + +template +void TList::insert_after(T key, T keyprev) +{ + while (root != 0 && root->key != keyprev) + root = root->pNext; + if (root == 0) + { + throw "Error! There is no such element"; + } + TList*n = new Node; + n->key = key; + n->pNext = root->pNext; + root->pNext = n; +}; + + +template +TLink* TList::Search(T key) +{ + TList*Nroot = root; + while (Nroot != 0) + { + if (Nroot->key == key) + { + return Nroot; + } + Nroot = Nroot->pNext; + } + throw "Error! There is no such element"; +}; + + +template +void TList::Remove(T key) +{ + if (root == 0) return; + TLink*node = root; + if (root->Key == key) + { + root = root->pNext; + delete node; + return; + } + while ((node->pNext != 0) && (node->pNext->Key != key)) + node = node->pNext; + if (node->pNext == 0) + { + throw "Error! There is no such element"; + } + TLink*node1 = node->pNext; + node->pNext = node1->pNext; + delete node1; +}; + +template +TLink* TList::Top()const +{ + return root; +}; + + +#endif diff --git a/Arefev_DA/lab1/include/TStack.h b/Arefev_DA/lab1/include/TStack.h new file mode 100644 index 000000000..7d9ceda8f --- /dev/null +++ b/Arefev_DA/lab1/include/TStack.h @@ -0,0 +1,80 @@ +#ifndef TSTACK_H +#define TSTACK_H +#include "TList.h" +#include +using namespace std; + +template +class TStack +{ +private: + TList*elems; +public: + TStack(); + ~TStack(); + TStack(const TStack& a); + void Push(T a); + T Pop(); + bool IsFull()const; + bool IsEmpty()const; +}; + + + +template +TStack::TStack() +{ + elems = new TList(); +}; + +template +TStack::~TStack() +{ + delete elems; +}; + +template +TStack::TStack(const TStack& a) +{ + elems = new TList(*(a.elems)); +}; + +template +void TStack::Push(T a) +{ + if (IsFull()) + throw "Error! Stack is full"; + elems->insert_start(a); +}; + +template +T TStack::Pop() +{ + if (IsEmpty()) + throw "Error! Stack is empty"; + T key = elems->Top()->Key; + elems->Remove(key); + return key; +}; + +template +bool TStack::IsEmpty()const +{ + return elems->Top() == 0; +}; + +template +bool TStack::IsFull()const +{ + T Key = -1; + try + { + elems->insert_start(Key); + elems->Remove(Key); + } + catch (...) { return true; } + return false; + +}; + +#endif diff --git a/Arefev_DA/lab1/samples/main.cpp b/Arefev_DA/lab1/samples/main.cpp new file mode 100644 index 000000000..be066a8a3 --- /dev/null +++ b/Arefev_DA/lab1/samples/main.cpp @@ -0,0 +1,33 @@ +#include "Function.h" +#include +#include +using namespace std; + +void main() +{ + setlocale(LC_ALL, "Russian"); + string s, a; + float Result; + cout << " : " << endl; + getline(cin, s); + try + { + s = st::correct(s); + } + catch (const char*ex) + { + cout << endl << ex << endl; + return; + } + a = st::postfix_form(s); + try + { + Result = st::calculations(a); + } + catch (const char*ex) + { + cout << endl << ex << endl; + return; + } + cout << endl << ": " << s <<" = " << Result << endl; +} \ No newline at end of file diff --git a/Arefev_DA/lab1/src/Function.cpp b/Arefev_DA/lab1/src/Function.cpp new file mode 100644 index 000000000..4bce10c9c --- /dev/null +++ b/Arefev_DA/lab1/src/Function.cpp @@ -0,0 +1,213 @@ +#include "TLink.h" +#include "TList.h" +#include "TStack.h" +#include "Function.h" +#include +#include +#include +using namespace std; + + +map st::readvalue(const string&s) +{ + map OpValue; + float value; + for (const char& c : s) + { + if ((c >= 'A') && (c <= 'Z')) + { + if (OpValue.count(c) == 0) + { + cout << c << " = "; + cin >> value; + OpValue[c] = value; + } + } + } + return OpValue; +} + + + + +int st::prioretet(char a) +{ + switch (a) + { + case '(': + return 1; + break; + case '+': + return 2; + break; + case '-': + return 2; + break; + case '*': + return 3; + break; + case '/': + return 3; + break; + } + return 0; +} + + + +string st::correct(string s) +{ + int count1 = 0; + int count2 = 0; + for (int i = 0; i < s.length(); i++) + { + if (s[i] == ' ') + { + s.erase(i, 1); + } + if (islower(s[i])) + { + s[i] = toupper(s[i]); + } + if (s[i] == '(') + count1++; + if (s[i] == ')') + count2++; + } + if (count1 != count2) + { + throw "! "; + } + cout << endl << " : " << endl; + return s; +} + + + +string st::postfix_form(string s) +{ + TStack stack1; + TStack stack2; + char top; + int m = s.length(); + cout << s << endl; + for (int i = 0; i < m; i++) + { + if ((s[i] >= 'A') && (s[i] <= 'Z')) + { + stack1.Push(s[i]); + continue; + } + if (s[i] == '(') + { + stack2.Push(s[i]); + continue; + } + if (s[i] == ')') + { + while ((top = stack2.Pop()) != '(') + { + stack1.Push(top); + } + continue; + } + if (!stack2.IsEmpty()) + { + top = stack2.Pop(); + if (prioretet(s[i]) > prioretet(top)) + { + stack2.Push(top); + stack2.Push(s[i]); + continue; + } + else + { + stack2.Push(top); + top = stack2.Pop(); + stack2.Push(top); + while ((prioretet(top) >= prioretet(s[i])) && (!stack2.IsEmpty())) + { + stack2.Pop(); + stack1.Push(top); + if (stack2.IsEmpty()) break; + top = stack2.Pop(); + stack2.Push(top); + } + stack2.Push(s[i]); + continue; + } + } + else + { + stack2.Push(s[i]); + continue; + } + } + while (!stack2.IsEmpty()) + { + char a = stack2.Pop(); + stack1.Push(a); + } + s = ""; + while (!stack1.IsEmpty()) + { + char a = stack1.Pop(); + s = a + s; + } + cout << endl << " : " << endl; + cout << s << endl << endl; + return s; +} + + + + +float st::calculations(string s) +{ + map values = readvalue(s); + TStack stack; + int m = s.length(); + float x, y, Result; + for (int i = 0; i < m; i++) + { + if ((s[i] >= 'A') && (s[i] <= 'Z')) + { + stack.Push(values[s[i]]); + } + if (s[i] == '+') + { + x = stack.Pop(); + y = stack.Pop(); + Result = y + x; + stack.Push(Result); + } + if (s[i] == '-') + { + x = stack.Pop(); + y = stack.Pop(); + Result = y - x; + stack.Push(Result); + } + if (s[i] == '*') + { + x = stack.Pop(); + y = stack.Pop(); + Result = y * x; + stack.Push(Result); + } + if (s[i] == '/') + { + x = stack.Pop(); + y = stack.Pop(); + if (x == 0) + { + throw "! "; + } + Result = y / x; + stack.Push(Result); + } + } + Result = stack.Pop(); + return Result; +} + diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/.suo b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/.suo new file mode 100644 index 000000000..d38c6ab07 Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/.suo differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Browse.VC.db b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Browse.VC.db new file mode 100644 index 000000000..41fecfde9 Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Browse.VC.db differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Browse.VC.opendb b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Browse.VC.opendb new file mode 100644 index 000000000..e18d4da9f Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Browse.VC.opendb differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Solution.VC.db b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Solution.VC.db new file mode 100644 index 000000000..0d8acbdfb Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Solution.VC.db differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Solution.VC.db-shm b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Solution.VC.db-shm new file mode 100644 index 000000000..bba9ca241 Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Solution.VC.db-shm differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Solution.VC.db-wal b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Solution.VC.db-wal new file mode 100644 index 000000000..651a3f8f7 Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/Solution.VC.db-wal differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/6f5edcfc7d465c02/DEJKSTRA.ipch b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/6f5edcfc7d465c02/DEJKSTRA.ipch new file mode 100644 index 000000000..05cd14b6e Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/6f5edcfc7d465c02/DEJKSTRA.ipch differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/74c37fc7a434df29/MAIN_DEJKSTRA.ipch b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/74c37fc7a434df29/MAIN_DEJKSTRA.ipch new file mode 100644 index 000000000..7152c3dea Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/74c37fc7a434df29/MAIN_DEJKSTRA.ipch differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/97d669da9d1f9cf9/SEPARATED_SETS.ipch b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/97d669da9d1f9cf9/SEPARATED_SETS.ipch new file mode 100644 index 000000000..861534b4d Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/97d669da9d1f9cf9/SEPARATED_SETS.ipch differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/a8d487dcfeb10423/KRASKAL.ipch b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/a8d487dcfeb10423/KRASKAL.ipch new file mode 100644 index 000000000..284523b66 Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/a8d487dcfeb10423/KRASKAL.ipch differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/ae6977d757bdf739/BINARY_SEARCH_TREE_BASED_PRIORITY_QUEUE.ipch b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/ae6977d757bdf739/BINARY_SEARCH_TREE_BASED_PRIORITY_QUEUE.ipch new file mode 100644 index 000000000..d26ac4a72 Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/ae6977d757bdf739/BINARY_SEARCH_TREE_BASED_PRIORITY_QUEUE.ipch differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/d317e50db04477ee/MAIN_KRASKAL_FOR_TREES.ipch b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/d317e50db04477ee/MAIN_KRASKAL_FOR_TREES.ipch new file mode 100644 index 000000000..69e4de5f6 Binary files /dev/null and b/Arefev_DA/lab2/build/Graph_Nproj/.vs/lab2/v15/ipch/AutoPCH/d317e50db04477ee/MAIN_KRASKAL_FOR_TREES.ipch differ diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Dejkstra/Dejkstra.vcxproj b/Arefev_DA/lab2/build/Graph_Nproj/Dejkstra/Dejkstra.vcxproj new file mode 100644 index 000000000..2a28d96b4 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Dejkstra/Dejkstra.vcxproj @@ -0,0 +1,154 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + 15.0 + {8A83950A-CB9A-4D71-8F86-0DA0577AB65C} + Win32Proj + Dejkstra + 8.1 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../../include + + + Console + ../Debug + Graph_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../../include + + + Console + true + true + ../Release + Graph_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + + + + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Dejkstra/Dejkstra.vcxproj.filters b/Arefev_DA/lab2/build/Graph_Nproj/Dejkstra/Dejkstra.vcxproj.filters new file mode 100644 index 000000000..78f73bba7 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Dejkstra/Dejkstra.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Файлы исходного кода + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Dejkstra/Dejkstra.vcxproj.user b/Arefev_DA/lab2/build/Graph_Nproj/Dejkstra/Dejkstra.vcxproj.user new file mode 100644 index 000000000..be2507870 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Dejkstra/Dejkstra.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/Graph_lib.vcxproj b/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/Graph_lib.vcxproj new file mode 100644 index 000000000..d1b71ece2 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/Graph_lib.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C} + Win32Proj + Graph_lib + 8.1 + + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + ../../../include + + + Windows + + + + + + + Level3 + Disabled + _DEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + ../../../include + + + Windows + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + true + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/Graph_lib.vcxproj.filters b/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/Graph_lib.vcxproj.filters new file mode 100644 index 000000000..6a1c38224 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/Graph_lib.vcxproj.filters @@ -0,0 +1,57 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Заголовочные файлы + + + Заголовочные файлы + + + Заголовочные файлы + + + Заголовочные файлы + + + Заголовочные файлы + + + Заголовочные файлы + + + Заголовочные файлы + + + + + Файлы исходного кода + + + Файлы исходного кода + + + Файлы исходного кода + + + Файлы исходного кода + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/Graph_lib.vcxproj.user b/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/Graph_lib.vcxproj.user new file mode 100644 index 000000000..be2507870 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/Graph_lib.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/ReadMe.txt b/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/ReadMe.txt new file mode 100644 index 000000000..d864e8ac6 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Graph_lib/ReadMe.txt @@ -0,0 +1,21 @@ +======================================================================== + СТАТИЧЕСКАЯ БИБЛИОТЕКА. Обзор проекта Graph_lib +======================================================================== + +Этот проект библиотеки Graph_lib создан автоматически с помощью мастера приложений. + +В составе проекта не созданы исходные файлы. + + +Graph_lib.vcxproj + Это основной файл проекта VC++, создаваемый с помощью мастера приложений. Он содержит данные о версии языка Visual C++, использованной для создания файла, а также сведения о платформах, конфигурациях и функциях проекта, выбранных с помощью мастера приложений. + +Graph_lib.vcxproj.filters + Это файл фильтров для проектов VC++, созданный с помощью мастера приложений. Он содержит сведения о сопоставлениях между файлами в вашем проекте и фильтрами. Эти сопоставления используются в среде IDE для группировки файлов с одинаковыми расширениями в одном узле (например CPP-файлы сопоставляются с фильтром "Исходные файлы"). + +///////////////////////////////////////////////////////////////////////////// +Прочие примечания. + +С помощью комментариев «TODO:» в мастере приложений обозначаются фрагменты исходного кода, которые необходимо дополнить или изменить. + +///////////////////////////////////////////////////////////////////////////// diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Kraskal/Kraskal.vcxproj b/Arefev_DA/lab2/build/Graph_Nproj/Kraskal/Kraskal.vcxproj new file mode 100644 index 000000000..933389330 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Kraskal/Kraskal.vcxproj @@ -0,0 +1,154 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + 15.0 + {104AA28F-A0CF-4FB3-85C6-0AEEECD1B912} + Win32Proj + Kraskal + 8.1 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../../include + + + Console + Graph_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + ../Debug + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../../include + + + Console + true + true + ../Release + Graph_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + + + + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Kraskal/Kraskal.vcxproj.filters b/Arefev_DA/lab2/build/Graph_Nproj/Kraskal/Kraskal.vcxproj.filters new file mode 100644 index 000000000..35268173a --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Kraskal/Kraskal.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Файлы исходного кода + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Main/Main.vcxproj b/Arefev_DA/lab2/build/Graph_Nproj/Main/Main.vcxproj new file mode 100644 index 000000000..93611c929 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Main/Main.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + 15.0 + {BACF2407-6F9F-48D8-90ED-3803A0269CCD} + Win32Proj + Main + 8.1 + dHeapSort + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../../include + + + Console + ../Debug + Graph_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../../include + + + Console + true + true + ../Release + Graph_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + + + + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Main/Main.vcxproj.filters b/Arefev_DA/lab2/build/Graph_Nproj/Main/Main.vcxproj.filters new file mode 100644 index 000000000..6ce803f12 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Main/Main.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Файлы исходного кода + + + Файлы исходного кода + + + + + Заголовочные файлы + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/Main/Main.vcxproj.user b/Arefev_DA/lab2/build/Graph_Nproj/Main/Main.vcxproj.user new file mode 100644 index 000000000..be2507870 --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/Main/Main.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Arefev_DA/lab2/build/Graph_Nproj/lab2.sln b/Arefev_DA/lab2/build/Graph_Nproj/lab2.sln new file mode 100644 index 000000000..7b0ef552e --- /dev/null +++ b/Arefev_DA/lab2/build/Graph_Nproj/lab2.sln @@ -0,0 +1,70 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.9 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Graph_lib", "Graph_lib\Graph_lib.vcxproj", "{2AF97C7C-6F25-467E-8C62-44FEBCEC864C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dHeapSort", "Main\Main.vcxproj", "{BACF2407-6F9F-48D8-90ED-3803A0269CCD}" + ProjectSection(ProjectDependencies) = postProject + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C} = {2AF97C7C-6F25-467E-8C62-44FEBCEC864C} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dejkstra", "Dejkstra\Dejkstra.vcxproj", "{8A83950A-CB9A-4D71-8F86-0DA0577AB65C}" + ProjectSection(ProjectDependencies) = postProject + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C} = {2AF97C7C-6F25-467E-8C62-44FEBCEC864C} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Kraskal", "Kraskal\Kraskal.vcxproj", "{104AA28F-A0CF-4FB3-85C6-0AEEECD1B912}" + ProjectSection(ProjectDependencies) = postProject + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C} = {2AF97C7C-6F25-467E-8C62-44FEBCEC864C} + EndProjectSection +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 + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C}.Debug|x64.ActiveCfg = Debug|x64 + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C}.Debug|x64.Build.0 = Debug|x64 + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C}.Debug|x86.ActiveCfg = Debug|Win32 + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C}.Debug|x86.Build.0 = Debug|Win32 + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C}.Release|x64.ActiveCfg = Release|x64 + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C}.Release|x64.Build.0 = Release|x64 + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C}.Release|x86.ActiveCfg = Release|Win32 + {2AF97C7C-6F25-467E-8C62-44FEBCEC864C}.Release|x86.Build.0 = Release|Win32 + {BACF2407-6F9F-48D8-90ED-3803A0269CCD}.Debug|x64.ActiveCfg = Debug|x64 + {BACF2407-6F9F-48D8-90ED-3803A0269CCD}.Debug|x64.Build.0 = Debug|x64 + {BACF2407-6F9F-48D8-90ED-3803A0269CCD}.Debug|x86.ActiveCfg = Debug|Win32 + {BACF2407-6F9F-48D8-90ED-3803A0269CCD}.Debug|x86.Build.0 = Debug|Win32 + {BACF2407-6F9F-48D8-90ED-3803A0269CCD}.Release|x64.ActiveCfg = Release|x64 + {BACF2407-6F9F-48D8-90ED-3803A0269CCD}.Release|x64.Build.0 = Release|x64 + {BACF2407-6F9F-48D8-90ED-3803A0269CCD}.Release|x86.ActiveCfg = Release|Win32 + {BACF2407-6F9F-48D8-90ED-3803A0269CCD}.Release|x86.Build.0 = Release|Win32 + {8A83950A-CB9A-4D71-8F86-0DA0577AB65C}.Debug|x64.ActiveCfg = Debug|x64 + {8A83950A-CB9A-4D71-8F86-0DA0577AB65C}.Debug|x64.Build.0 = Debug|x64 + {8A83950A-CB9A-4D71-8F86-0DA0577AB65C}.Debug|x86.ActiveCfg = Debug|Win32 + {8A83950A-CB9A-4D71-8F86-0DA0577AB65C}.Debug|x86.Build.0 = Debug|Win32 + {8A83950A-CB9A-4D71-8F86-0DA0577AB65C}.Release|x64.ActiveCfg = Release|x64 + {8A83950A-CB9A-4D71-8F86-0DA0577AB65C}.Release|x64.Build.0 = Release|x64 + {8A83950A-CB9A-4D71-8F86-0DA0577AB65C}.Release|x86.ActiveCfg = Release|Win32 + {8A83950A-CB9A-4D71-8F86-0DA0577AB65C}.Release|x86.Build.0 = Release|Win32 + {104AA28F-A0CF-4FB3-85C6-0AEEECD1B912}.Debug|x64.ActiveCfg = Debug|x64 + {104AA28F-A0CF-4FB3-85C6-0AEEECD1B912}.Debug|x64.Build.0 = Debug|x64 + {104AA28F-A0CF-4FB3-85C6-0AEEECD1B912}.Debug|x86.ActiveCfg = Debug|Win32 + {104AA28F-A0CF-4FB3-85C6-0AEEECD1B912}.Debug|x86.Build.0 = Debug|Win32 + {104AA28F-A0CF-4FB3-85C6-0AEEECD1B912}.Release|x64.ActiveCfg = Release|x64 + {104AA28F-A0CF-4FB3-85C6-0AEEECD1B912}.Release|x64.Build.0 = Release|x64 + {104AA28F-A0CF-4FB3-85C6-0AEEECD1B912}.Release|x86.ActiveCfg = Release|Win32 + {104AA28F-A0CF-4FB3-85C6-0AEEECD1B912}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0B76C663-3EC5-4928-90DC-710DFC71EDB4} + EndGlobalSection +EndGlobal diff --git "a/Arefev_DA/lab2/doc/D-\320\272\321\203\321\207\320\270.doc" "b/Arefev_DA/lab2/doc/D-\320\272\321\203\321\207\320\270.doc" new file mode 100644 index 000000000..4d62a2c56 Binary files /dev/null and "b/Arefev_DA/lab2/doc/D-\320\272\321\203\321\207\320\270.doc" differ diff --git a/Arefev_DA/lab2/include/binary_search_tree.h b/Arefev_DA/lab2/include/binary_search_tree.h new file mode 100644 index 000000000..96d2b8139 --- /dev/null +++ b/Arefev_DA/lab2/include/binary_search_tree.h @@ -0,0 +1,164 @@ +#pragma once +#include "tree_node.h" + +#define NULL nullptr + +template +class BinarySearchTree +{ + Node* root; // +public: + BinarySearchTree(); + BinarySearchTree(const BinarySearchTree& tree); + ~BinarySearchTree(); + //: + Node* Search(T key); + Node* Searchmin(Node* x); + Node* Searchmax(Node* x); + Node* Searchnext(Node* curr); + Node* Searchprev(Node* curr); + void Insert(Node* x); + void Remove(Node* z); + Node* GetRoot() { return root; }; +}; + +template +BinarySearchTree::BinarySearchTree() +{ + root = NULL; +} + +template +BinarySearchTree::BinarySearchTree(const BinarySearchTree& tree) +{ +} + +template +BinarySearchTree::~BinarySearchTree() +{ + while (root != NULL) + { + Node* tmp = Searchmax(root); + Remove(tmp); + } + +} + +//: +template +Node* BinarySearchTree::Search(T data) +{ + Node *curr = root; + while (curr != NULL && curr->key != data) + { + if (data < curr->key) curr = curr->pLeft; + else curr = curr->pRight; + } + return curr; +} + +template +Node* BinarySearchTree::Searchmin(Node* x) +{ + Node* curr = x; + while (curr->pLeft != NULL) + { + curr = curr->pLeft; + } + return curr; +} + +template +Node* BinarySearchTree::Searchmax(Node* x) +{ + Node* curr = x; + while (curr->pRight != NULL) + { + curr = curr->pRight; + } + return curr; + +} + +template +Node* BinarySearchTree::Searchnext(Node* curr) +{ + Node *res = NULL; + if (curr->pRight != NULL) + { + res = Searchmin(curr); + return res; + } + res = curr->pParent; + Node *tmp = curr; + while (res != NULL && tmp == res->pRight) + { + tmp = res; + res = res->pParent; + } + return res; + +} + +template +Node* BinarySearchTree::Searchprev(Node* curr) +{ + Node *res = NULL; + if (curr->pLeft != NULL) + { + res = Searchmax(curr); + return res; + } + res = curr->pParent; + Node *tmp = curr; + while (res != NULL && tmp == res->pLeft) + { + tmp = res; + res = res->pParent; + } + return res; + +} + +template +void BinarySearchTree::Insert(Node*x) +{ + if (root == NULL) + { + root = x; + return; + } + Node *node = root, *y; + while (node != NULL) + { + y = node; + if (x->key < node->key) node = node->pLeft; + else node = node->pRight; + } + x->pParent = y; + if (x->key < y->key) y->pLeft = x; + else y->pRight = x; +} + +template +void BinarySearchTree::Remove(Node*z) +{ + Node *y = NULL, *x = NULL; + if (z->pLeft != NULL && z->pRight != NULL) + { + y = Searchnext(z); + } + else y = z; + if (y->pLeft != NULL) x = y->pLeft; + else x = y->pRight; + if (x != NULL) x->pParent = y->pParent; + if (y->pParent != NULL) + { + if (y = y->pParent->pLeft) y->pParent->pLeft = x; + else y->pParent->pRight = x; + } + if (y != z) + { + z->key = y->key; + } +} \ No newline at end of file diff --git a/Arefev_DA/lab2/include/binary_search_tree_based_priority_queue.h b/Arefev_DA/lab2/include/binary_search_tree_based_priority_queue.h new file mode 100644 index 000000000..0d7afb976 --- /dev/null +++ b/Arefev_DA/lab2/include/binary_search_tree_based_priority_queue.h @@ -0,0 +1,50 @@ +#pragma once +#include "binary_search_tree.h" +#include "priority_queue.h" + +#define NULL nullptr + +template +class BinarySearchTreeBasedPriorityQueue: public PriorityQueue +{ +public: + BinarySearchTree* tree; + BinarySearchTreeBasedPriorityQueue(); + ~BinarySearchTreeBasedPriorityQueue(); + void push(T val); + T pop(); + bool IsEmpty(); +}; + +template +BinarySearchTreeBasedPriorityQueue::BinarySearchTreeBasedPriorityQueue() +{ +} + +template +BinarySearchTreeBasedPriorityQueue::~BinarySearchTreeBasedPriorityQueue() +{ +} + +template +void BinarySearchTreeBasedPriorityQueue::push(T val) +{ + Node* tmp; + tmp->key = val; + tree->Insert(tmp); +} + +template +T BinarySearchTreeBasedPriorityQueue::pop() +{ + Node* node = tree->Searchmin(tree->GetRoot()); + tree->Remove(node); + return node->key; +} + +template +bool BinarySearchTreeBasedPriorityQueue::IsEmpty() +{ + if (tree->GetRoot()==NULL) return true; + else return false; +} diff --git a/Arefev_DA/lab2/include/dejkstra.h b/Arefev_DA/lab2/include/dejkstra.h new file mode 100644 index 000000000..5731f8469 --- /dev/null +++ b/Arefev_DA/lab2/include/dejkstra.h @@ -0,0 +1,9 @@ +#pragma once +#include "graph.h" +#include "priority_queue.h" + +class AlgoritmDejkstri +{ +public: + void Dejkstra(Graph* g, PriorityQueue* q); +}; \ No newline at end of file diff --git a/Arefev_DA/lab2/include/dheap.h b/Arefev_DA/lab2/include/dheap.h new file mode 100644 index 000000000..e2cc39c08 --- /dev/null +++ b/Arefev_DA/lab2/include/dheap.h @@ -0,0 +1,168 @@ +#pragma once + +#include "graph.h" +#include "priority_queue.h" +#include + +using namespace std; + +template +class DHeap +{ + int d = 2;// d- + T* keys; // + int n; // + int k;// +public: + DHeap() {}; + DHeap(int MaxSize); + DHeap(T* edges, int size); + DHeap(Graph graph); + ~DHeap(); + + // + void transpose(int i, int j); + void emerge(int i); // + void sinking(int i); // + int minchild(int id); + T deleteminkey(); + void insert(const T& key); + void makeitheap(); // + + // + int GetMaxSize() { return n; }; + int GetCurrSize() { return k; }; + void ChangeCurrSize(int curr) { k = curr; }; + + // + void Print(); + +}; + +template +DHeap::DHeap(T* edges, int size) +{ + n = size; + keys = new T[n]; + for (int i = 0;i < n;i++) + { + keys[i] = edges[i]; + } + k = n; +}; + +template +DHeap::~DHeap() +{ + delete[] keys; +} + +template +DHeap::DHeap(int MaxSize) +{ + n = MaxSize; + k = 0; + keys = new T[n]; +}; + +template +DHeap::DHeap(Graph graph) +{ + +}; + +template +void DHeap::transpose(int i, int j) +{ + T tmp = keys[i]; + keys[i] = keys[j]; + keys[j] = tmp; +} + +template +void DHeap::insert(const T& key) +{ + if (k >= n) throw("Error insert"); + keys[k] = key; + emerge(k); + k++; +} + +template +void DHeap::emerge(int i) +{ + int p = (i - 1) / d; + while (i>0) + { + if (keys[p] > keys[i]) + { + transpose(p, i); + i = p; + p = (i - 1) / d; + } + else break; + } +} + +template +void DHeap::sinking(int i) +{ + int c = minchild(i); + while ((c != -1) && (keys[c] < keys[i])) + { + transpose(i, c); + i = c; + c = minchild(i); + } + +} + +template +int DHeap::minchild(int id) +{ + int f = id*d + 1; + if (f > k-1) + return -1; + + int l = (id*d + d < k-1)? id*d + d : k-1; + int c; + + T minKey = keys[f]; + c = f; + for (int j = f + 1; j <= l; j++) { + if (minKey > keys[j]) { + minKey = keys[j]; + c = j; + } + } + return c; +} + +template +T DHeap::deleteminkey() +{ + T tmp = keys[0]; + transpose(0,k-1); + k--; + sinking(0); + return tmp; +} + +template +void DHeap::makeitheap() +{ + for (int i = (k - 1); i >= 0; i--) + { + sinking(i); + } +} + +template +void DHeap::Print() +{ + for (int i = 0;i < n;i++) + { + cout << keys[i]<<" "; + } +} + diff --git a/Arefev_DA/lab2/include/dheap_sort.h b/Arefev_DA/lab2/include/dheap_sort.h new file mode 100644 index 000000000..1186b26a5 --- /dev/null +++ b/Arefev_DA/lab2/include/dheap_sort.h @@ -0,0 +1,8 @@ +#pragma once +#include "dheap.h" + +class PiramidSortBasedDHeap +{ +public: + void PiramidSort(int* keys, int n); +}; \ No newline at end of file diff --git a/Arefev_DA/lab2/include/graph.h b/Arefev_DA/lab2/include/graph.h new file mode 100644 index 000000000..817d72b6f --- /dev/null +++ b/Arefev_DA/lab2/include/graph.h @@ -0,0 +1,63 @@ +#pragma once +#include + +using namespace std; + +class Edge +{ + int N; // + int K; // + float W; // +public: + Edge() {}; + ~Edge() {}; + Edge(int i, int j, float k); + Edge(const Edge& e); + + int GetStart() { return N; }; + int GetFinish() { return K; }; + float GetWeight() { return W; }; + + bool operator<(const Edge& e); + bool operator>(const Edge& e) { return !(*this < e); }; + Edge& operator=(const Edge& e); + friend ostream& operator<<(ostream& os, const Edge& e); +}; + +class Vertex +{ + int id; + float mark; +public: + Vertex() { id = -1; mark = 1000000.0; }; + ~Vertex() {}; + Vertex(int i, float k); + + int GetId() { return id; }; + float GetMark() { return mark; }; + void SetMark(float v) { mark = v; } + + bool operator<(const Vertex& e); + bool operator>(const Vertex& e) { return !(*this < e);}; + Vertex& operator=(const Vertex& e); + +}; + + +class Graph // , +{ + int n; // + int m; // + Edge* edges; +public: + Graph(int k, int l); + Graph(int k, int l, Edge* edg); + ~Graph(); + float GetEdgeWeight(int n, int k); + int GetN() { return n; }; + int GetM() { return m; }; + Edge GetEdge(int i) { return edges[i]; }; +}; + + + diff --git a/Arefev_DA/lab2/include/kraskal.h b/Arefev_DA/lab2/include/kraskal.h new file mode 100644 index 000000000..e9295d8eb --- /dev/null +++ b/Arefev_DA/lab2/include/kraskal.h @@ -0,0 +1,9 @@ +#pragma once +#include "graph.h" +#include "priority_queue_based_dheap.h" + +class AlgoritmKraskala +{ +public: + Edge* Kraskal(Graph*g,PriorityQueue* q); +}; \ No newline at end of file diff --git a/Arefev_DA/lab2/include/priority_queue.h b/Arefev_DA/lab2/include/priority_queue.h new file mode 100644 index 000000000..85edc7c55 --- /dev/null +++ b/Arefev_DA/lab2/include/priority_queue.h @@ -0,0 +1,53 @@ +#pragma once +#include "dheap.h" + +template +class PriorityQueue +{ +public: + PriorityQueue() {}; + PriorityQueue(int Maxsize); + virtual void push(T val); + virtual T pop(); + //virtual T get(); + virtual bool IsEmpty(); + virtual void refresh(); +}; + +template +PriorityQueue::PriorityQueue(int Maxsize) +{ + +} + +template +void PriorityQueue::push(T val) +{ + +} + +template +void PriorityQueue::refresh() +{ + +} + +template +T PriorityQueue::pop() +{ + T tmp; + return tmp; +} + +//template +//T PriorityQueue::get() +//{ +// Edge tmp; +// return tmp; +//} + +template +bool PriorityQueue::IsEmpty() +{ + return true; +} \ No newline at end of file diff --git a/Arefev_DA/lab2/include/priority_queue_based_dheap.h b/Arefev_DA/lab2/include/priority_queue_based_dheap.h new file mode 100644 index 000000000..d00698379 --- /dev/null +++ b/Arefev_DA/lab2/include/priority_queue_based_dheap.h @@ -0,0 +1,62 @@ +#pragma once +#include "priority_queue.h" +#include "dheap.h" +#include "graph.h" + +template +class PriorityQueueBasedDHeap: public PriorityQueue +{ +public: + DHeap* H; + PriorityQueueBasedDHeap(int n); + ~PriorityQueueBasedDHeap(); + void push(T val); + T pop(); + // T get(); + bool IsEmpty(); + void refresh(); +}; + + +template +PriorityQueueBasedDHeap::PriorityQueueBasedDHeap(int n) +{ + H = new DHeap(n); +} + +template +PriorityQueueBasedDHeap::~PriorityQueueBasedDHeap() +{ + +} + +template +void PriorityQueueBasedDHeap::push(T val) +{ + H->insert(val); +} + +template +void PriorityQueueBasedDHeap::refresh() +{ + H->makeitheap(); +} + +template +T PriorityQueueBasedDHeap::pop() +{ + T tmp = H->deleteminkey(); + return tmp; +} + +//template +//T PriorityQueueBasedDHeap::get() +//{ +//} + +template +bool PriorityQueueBasedDHeap::IsEmpty() +{ + if( H->GetCurrSize() == 0 )return true; + else return false; +} diff --git a/Arefev_DA/lab2/include/separated_sets.h b/Arefev_DA/lab2/include/separated_sets.h new file mode 100644 index 000000000..e09836e7d --- /dev/null +++ b/Arefev_DA/lab2/include/separated_sets.h @@ -0,0 +1,12 @@ +#pragma once + +class SeparatedSets { + int n; + int* M; +public: + SeparatedSets(int m); // + ~SeparatedSets() { delete[] M; }; + void Create (int singl); + void Unite(int i, int j); + int DefineSubset(int i); +}; \ No newline at end of file diff --git a/Arefev_DA/lab2/include/tree_node.h b/Arefev_DA/lab2/include/tree_node.h new file mode 100644 index 000000000..f2db4e684 --- /dev/null +++ b/Arefev_DA/lab2/include/tree_node.h @@ -0,0 +1,14 @@ +#pragma once +# +template +class Node +{ +public: + T key; + Node* pLeft; + Node* pRight; + Node* pParent; + Node() {}; + Node(T k) { key = k; }; + ~Node() {}; +}; \ No newline at end of file diff --git a/Arefev_DA/lab2/samples/main_dejkstra.cpp b/Arefev_DA/lab2/samples/main_dejkstra.cpp new file mode 100644 index 000000000..434af32ca --- /dev/null +++ b/Arefev_DA/lab2/samples/main_dejkstra.cpp @@ -0,0 +1,43 @@ +#include +#include "graph.h" +#include "priority_queue.h" +#include "priority_queue_based_dheap.h" +#include "dejkstra.h" + +using namespace std; + +int main() +{ + setlocale(LC_ALL, "Russian"); + int n, m; + + cout << " " << endl; + cin >> n; + cout << " " << endl; + cin >> m; + Edge* E = new Edge[m]; + int l = 0;// + for (int i = 0; i < n-1; i++) + { + cout << " , 0. , " << i << endl; + for (int j = i + 1; j < n; j++) + { + float w; + cout << " " << j << ": "; + cin >> w; + cout << endl; + if (w != 0) { + Edge tmp(i, j, w); + E[l] = tmp; + l++; + } + if (l > m) cout << "Error!" << endl; + } + } + + Graph G(n, m, E); + PriorityQueue* Q = new PriorityQueueBasedDHeap(n); + AlgoritmDejkstri AD; + AD.Dejkstra(&G, Q); + return 0; +} \ No newline at end of file diff --git a/Arefev_DA/lab2/samples/main_dheap_sort.cpp b/Arefev_DA/lab2/samples/main_dheap_sort.cpp new file mode 100644 index 000000000..a65e37783 --- /dev/null +++ b/Arefev_DA/lab2/samples/main_dheap_sort.cpp @@ -0,0 +1,26 @@ +#include +#include + +using namespace std; + +int main() +{ + setlocale(LC_ALL, "Russian"); + + int n; + int* mas; + PiramidSortBasedDHeap D; + + cout << " :" << endl; + cin >> n; + mas = new int[n]; + cout << " :" << endl; + for (int i = 0;i < n;i++) + { + cin >> mas[i]; + } + + D.PiramidSort(mas, n); + + return 0; +} \ No newline at end of file diff --git a/Arefev_DA/lab2/samples/main_kraskal.cpp b/Arefev_DA/lab2/samples/main_kraskal.cpp new file mode 100644 index 000000000..2c85d119a --- /dev/null +++ b/Arefev_DA/lab2/samples/main_kraskal.cpp @@ -0,0 +1,46 @@ +#include +#include "kraskal.h" +#include "graph.h" + +using namespace std; + +int main() +{ + setlocale(LC_ALL, "Russian"); + + int n,m; + + cout << " " << endl; + cin >> n; + cout << " " << endl; + cin >> m; + Edge* E = new Edge[m]; + int l = 0;// + for (int i = 0; i < (n-1); i++) + { + cout << " , 0. , "<< i << endl; + for (int j = i+1; j < n; j++) + { + float w; + cout << " " << j << ": "; + cin >> w; + cout << endl; + if (w != 0) { + Edge tmp(i, j, w); + E[l] = tmp; + l++; + } + if (l > m) cout << "Error!" << endl; + } + } + + Graph G(n, m, E); + PriorityQueue* Q = new PriorityQueueBasedDHeap(m); + Edge* WE = new Edge[n - 1]; + AlgoritmKraskala AK; + WE = AK.Kraskal(&G, Q); + for (int i = 0;i < n-1;i++) { + cout << "(" << WE[i].GetStart() << "," << WE[i].GetFinish() << ")" << ","; + } + return 0; +} \ No newline at end of file diff --git a/Arefev_DA/lab2/samples/main_kraskal_for_trees.cpp b/Arefev_DA/lab2/samples/main_kraskal_for_trees.cpp new file mode 100644 index 000000000..05fb8d921 --- /dev/null +++ b/Arefev_DA/lab2/samples/main_kraskal_for_trees.cpp @@ -0,0 +1,48 @@ +#include "binary_search_tree.h" +#include "priority_queue.h" +#include "graph.h" +#include "binary_search_tree_based_priority_queue.h" +#include "kraskal.h" +#include + +using namespace std; + +int main(void) +{ + setlocale(LC_ALL, "Russian"); + + int n, m; + + cout << " " << endl; + cin >> n; + cout << " " << endl; + cin >> m; + Edge* E = new Edge[m]; + int l = 0;// + for (int i = 0; i < n; i++) + { + cout << " , " << i << endl; + for (int j = i + 1; j < n; j++) + { + float w; + cout << " " << j << ": "; + cin >> w; + cout << endl; + if (w != 0) { + Edge tmp(i, j, w); + E[l] = tmp; + l++; + } + if (l > m) cout << "Error!" << endl; + } + } + + Graph G(n, m, E); + PriorityQueue* Q = new BinarySearchTreeBasedPriorityQueue; + Edge* WE = new Edge[n - 1]; + AlgoritmKraskala AK; + WE = AK.Kraskal(&G, Q); + return 0; +} + + \ No newline at end of file diff --git a/Arefev_DA/lab2/src/binary_search_tree.cpp b/Arefev_DA/lab2/src/binary_search_tree.cpp new file mode 100644 index 000000000..4e9f55680 --- /dev/null +++ b/Arefev_DA/lab2/src/binary_search_tree.cpp @@ -0,0 +1,3 @@ +#include "binary_search_tree.h" + + diff --git a/Arefev_DA/lab2/src/dejkstra.cpp b/Arefev_DA/lab2/src/dejkstra.cpp new file mode 100644 index 000000000..0d5de237c --- /dev/null +++ b/Arefev_DA/lab2/src/dejkstra.cpp @@ -0,0 +1,95 @@ +#include "dejkstra.h" +#include + +using namespace std; + +//#define MAX 1000; + +void AlgoritmDejkstri::Dejkstra(Graph* g, PriorityQueue* q) +{ + + int n = g->GetN(); + int m = g->GetM(); + + Vertex* dist = new Vertex[n]; + + int* up = new int[n]; + + char* lables = new char[m]; + for (int i = 0;i < m;i++) + { + lables[i] = 0; + } + + up[0] = 0; + Vertex trr(0, 0); + dist[0] = trr; + + q->push(dist[0]); + + for (int i = 1; i < n; i++) { + Vertex tmp(i,100000); + up[i] = i; + dist[i] = tmp; + } + + Edge** edges = new Edge*[m]; + for (int i = 0;i < m;i++) + { + edges[i] = new Edge(g->GetEdge(i)); + } + + while (!q->IsEmpty()) + { + int vConsidered = q->pop().GetId(); //vConsidered - currid + float delta; + + for (int i = 0; i < m; i++) + { + int vIncident = -1; + if (edges[i]->GetFinish() == vConsidered && lables[i]==0) + vIncident = edges[i]->GetStart(); + if (edges[i]->GetStart() == vConsidered && lables[i]==0) + vIncident = edges[i]->GetFinish(); + if (vIncident == -1) continue; + + lables[i] = 1; + + float way = dist[vConsidered].GetMark() + g->GetEdgeWeight(vConsidered, vIncident); + if (way <= 0) continue; + delta = dist[vIncident].GetMark() - way; + if (delta > 0) + { + dist[vIncident].SetMark(way); + up[vIncident] = vConsidered; + q->push(dist[vIncident]); + q->refresh(); + } + } + } + float* Distance = new float[n]; + for (int i = 0; i < n; i++) + Distance[i] = dist[i].GetMark(); + + // + for (int i = 0;i < n;i++) + { + cout << Distance[i] << " "; + } + cout << endl; + for (int i = 0;i < n;i++) + { + cout << up[i] << " "; + } + // + for (int i = 0;i < m;i++) + { + delete edges[i]; + } + delete[]edges; + + delete[]up; + + delete[]dist; + +} \ No newline at end of file diff --git a/Arefev_DA/lab2/src/dheap.cpp b/Arefev_DA/lab2/src/dheap.cpp new file mode 100644 index 000000000..39346cf2a --- /dev/null +++ b/Arefev_DA/lab2/src/dheap.cpp @@ -0,0 +1 @@ +#include "dheap.h" diff --git a/Arefev_DA/lab2/src/dheap_sort.cpp b/Arefev_DA/lab2/src/dheap_sort.cpp new file mode 100644 index 000000000..e03049efc --- /dev/null +++ b/Arefev_DA/lab2/src/dheap_sort.cpp @@ -0,0 +1,14 @@ +#include "dheap_sort.h" + +void PiramidSortBasedDHeap::PiramidSort(int* keys, int n) +{ + DHeap heap(keys,n); + heap.makeitheap(); + while (heap.GetCurrSize() > 1) + { + heap.transpose(0, heap.GetCurrSize() - 1); + heap.ChangeCurrSize(heap.GetCurrSize()-1); + heap.sinking(0); + } + heap.Print(); +} \ No newline at end of file diff --git a/Arefev_DA/lab2/src/graph.cpp b/Arefev_DA/lab2/src/graph.cpp new file mode 100644 index 000000000..80b363f6a --- /dev/null +++ b/Arefev_DA/lab2/src/graph.cpp @@ -0,0 +1,90 @@ +#include "graph.h" +#include + +using namespace std; + +Vertex::Vertex(int i, float k) +{ + id = i; + mark = k; +} +bool Vertex::operator<(const Vertex& e) +{ + if (mark < e.mark) + { + return true; + } + else return false; +} +Vertex& Vertex::operator=(const Vertex& e) +{ + id = e.id; + mark = e.mark; + return *this; +} + ostream& operator<<(ostream& os, const Edge& e) + { + cout << e.W <<" "; + return os; + } + + bool Edge::operator<(const Edge& e) + { + if (W < e.W) return true; + else return false; + } + +Edge::Edge(int i, int j, float k) +{ + N = i; + K = j; + W = k; +} + +Edge& Edge::operator=(const Edge& e) +{ + W = e.W; + K = e.K; + N = e.N; + return *this; +} +Edge::Edge(const Edge& e) +{ + W = e.W; + K = e.K; + N = e.N; +} + +Graph::Graph(int k, int l) +{ + n = k; + m = l; + edges = new Edge[m]; +} + + +Graph::Graph(int k, int l, Edge* edg) +{ + n = k; + m = l; + edges = new Edge[m]; + for (int i = 0; i < m; i++) + { + edges[i] = edg[i]; + } +} + +Graph::~Graph() +{ + delete[] edges; +} + +float Graph::GetEdgeWeight(int n, int k) +{ + for (int i = 0; i < m;i++) + { + if (((edges[i].GetStart() == n) && (edges[i].GetFinish() == k))||((edges[i].GetStart() == k)&&(edges[i].GetFinish() == n))) + return edges[i].GetWeight(); + } + return -1; +} diff --git a/Arefev_DA/lab2/src/kraskal.cpp b/Arefev_DA/lab2/src/kraskal.cpp new file mode 100644 index 000000000..cc4d6c1d2 --- /dev/null +++ b/Arefev_DA/lab2/src/kraskal.cpp @@ -0,0 +1,30 @@ +#include "kraskal.h" +#include "separated_sets.h" + + +Edge* AlgoritmKraskala::Kraskal(Graph*g, PriorityQueue* queue) +{ + SeparatedSets U(g->GetN()); + int nE = g->GetN() - 1; // + int kE = 0; // + Edge* E = new Edge[nE]; + for (int i = 0;i < g->GetM();i++) + { + queue->push(g->GetEdge(i)); + } + while ((!queue->IsEmpty()) &&(kE < nE)) + { + Edge Tmp = queue->pop(); + int A = Tmp.GetStart(), B = Tmp.GetFinish(); + int uA = U.DefineSubset(A); + int uB = U.DefineSubset(B); + if (uA != uB) + { + U.Unite(uA,uB); + E[kE] = Tmp; + kE++; + } + } + + return E; +} \ No newline at end of file diff --git a/Arefev_DA/lab2/src/priority_queue.cpp b/Arefev_DA/lab2/src/priority_queue.cpp new file mode 100644 index 000000000..3140e6b24 --- /dev/null +++ b/Arefev_DA/lab2/src/priority_queue.cpp @@ -0,0 +1 @@ +#include "priority_queue.h" \ No newline at end of file diff --git a/Arefev_DA/lab2/src/priority_queue_based_dheap.cpp b/Arefev_DA/lab2/src/priority_queue_based_dheap.cpp new file mode 100644 index 000000000..6680ecd97 --- /dev/null +++ b/Arefev_DA/lab2/src/priority_queue_based_dheap.cpp @@ -0,0 +1 @@ +#include "priority_queue_based_dheap.h" diff --git a/Arefev_DA/lab2/src/separated_sets.cpp b/Arefev_DA/lab2/src/separated_sets.cpp new file mode 100644 index 000000000..7ecf1a335 --- /dev/null +++ b/Arefev_DA/lab2/src/separated_sets.cpp @@ -0,0 +1,32 @@ +#include "separated_sets.h" +#include + +using namespace std; + +SeparatedSets::SeparatedSets(int m) +{ + n = m; + M = new int[n]; + for (int i = 0; i < n; i++) + { + M[i] = i; + } +} +void SeparatedSets::Create(int singl) +{ + if (singl > n) + cout << "Error"; + else + M[singl] = singl; +} +void SeparatedSets::Unite(int i, int j) +{ + for (int k = 0; k < n; k++) + { + if (M[k] == i) M[k] = j; + } +} +int SeparatedSets::DefineSubset(int i) +{ + return M[i]; +} \ No newline at end of file diff --git a/Arefev_DA/lab2/src/tree_node.cpp b/Arefev_DA/lab2/src/tree_node.cpp new file mode 100644 index 000000000..167619dcc --- /dev/null +++ b/Arefev_DA/lab2/src/tree_node.cpp @@ -0,0 +1 @@ +#include "tree_node.h"