From ecdb490c35ff5c9d3e0b14d5fe4e996f3ec2868d Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Sun, 21 Dec 2025 10:50:53 +0700 Subject: [PATCH] chore: migrate --- .gitignore | 41 ++++++++ List.cpp | 265 +++++++++++++++++++++++++++++++++++++++++++++++++ Nhut/List.cpp | 265 +++++++++++++++++++++++++++++++++++++++++++++++++ Nhut/List.h | 39 ++++++++ Nhut/Poly.cpp | 41 ++++++++ Nhut/Queue.cpp | 23 +++++ Nhut/Queue.h | 18 ++++ Nhut/Stack.cpp | 23 +++++ Nhut/Stack.h | 18 ++++ Poly | Bin 0 -> 19392 bytes Poly.cpp | 41 ++++++++ Queue.cpp | 23 +++++ Queue.h | 18 ++++ Stack.cpp | 23 +++++ Stack.h | 18 ++++ makefile | 12 +++ 16 files changed, 868 insertions(+) create mode 100644 .gitignore create mode 100644 List.cpp create mode 100644 Nhut/List.cpp create mode 100644 Nhut/List.h create mode 100644 Nhut/Poly.cpp create mode 100644 Nhut/Queue.cpp create mode 100644 Nhut/Queue.h create mode 100644 Nhut/Stack.cpp create mode 100644 Nhut/Stack.h create mode 100644 Poly create mode 100644 Poly.cpp create mode 100644 Queue.cpp create mode 100644 Queue.h create mode 100644 Stack.cpp create mode 100644 Stack.h create mode 100644 makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4fb281 --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Linker files +*.ilk + +# Debugger Files +*.pdb + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# debug information files +*.dwo diff --git a/List.cpp b/List.cpp new file mode 100644 index 0000000..8b6c81f --- /dev/null +++ b/List.cpp @@ -0,0 +1,265 @@ +#include "List.h" +#include "Queue.h" +#include "Stack.h" + +List::List() +{ + pHead = NULL; + count = 0; +} + +void List::addLast(int newdata) +{ + Node *pNew = new Node; + pNew->data = newdata; + if (pHead == NULL) + { + pHead = pNew; + ++count; + return; + } + Node *pTemp = pHead; + while (pTemp->next != NULL) + { + pTemp = pTemp->next; + } + pTemp->next = pNew; + ++count; +} + +void List::addConstant(int nConstant) +{ + Node *pTemp = pHead; + if (pTemp == NULL) + return; + while (pTemp->next != NULL) + pTemp = pTemp->next; + pTemp->data += nConstant; + return; +} + +void List::addFirst(int newdata) +{ + Node *pTemp = new Node; + pTemp->data = newdata; + pTemp->next = pHead; + pHead = pTemp; + count++; +} + +void List::display() +{ + Node *pTemp = pHead; + while (pTemp != NULL) + { + cout << pTemp->data << " "; + pTemp = pTemp->next; + } + cout << endl; +} + +void List::displayPoly() +{ + Node *pTemp = pHead; + int i = 0; + while (pTemp != NULL) + { + int index = count - 1 - i; + if (pTemp->data != 0) + { + if (pTemp->data > 0) + { + if (i != 0) + cout << "+"; + } + cout << pTemp->data; + if (index == 1) + cout << "x"; + else if (index > 1) + cout << "x^" << index; + } + ++i; + pTemp = pTemp->next; + } + cout << endl; +} + +void List::removeFirst() +{ + if (pHead == NULL) + return; + Node *pDel = pHead; + pHead = pHead->next; + delete pDel; + --count; +} + +void List::removeLast() +{ + if (pHead == NULL) + return; + Node *pTemp = pHead; + if (count == 1) + { + pHead = NULL; + delete pTemp; + count = 0; + return; + } + Node *pPrev = NULL; + while (pTemp->next != NULL) + { + pPrev = pTemp; + pTemp = pTemp->next; + } + pPrev->next = NULL; + delete pTemp; + --count; +} + +int List::returnFirst() +{ + if (pHead == NULL) + return 0; + return pHead->data; +} + +int List::returnLast() +{ + if (pHead == NULL) + return 0; + Node *pTemp = pHead; + while (pTemp->next != NULL) + pTemp = pTemp->next; + return pTemp->data; +} + +List::~List() +{ + Node *pTemp = pHead; + while (pTemp != NULL) + { + pTemp = pTemp->next; + delete pHead; + pHead = pTemp; + } +} + +List *addPoly(List *list1, List *list2) +{ + if (list1 == NULL || list2 == NULL) + return NULL; + int i = list1->count, + j = list2->count; + Node *pHead1 = list1->pHead; + Node *pHead2 = list2->pHead; + if (i <= 0 || j <= 0) + return NULL; + if (i > j) + { + while (i > j) + { + pHead1 = pHead1->next; + --i; + } + } + else + { + while (j > i) + { + pHead2 = pHead2->next; + --j; + } + } + List *ret = new List; + while (i > 0) + { + int t = pHead1->data + pHead2->data; + ret->addLast(t); + pHead1 = pHead1->next; + pHead2 = pHead2->next; + --i; + } + return ret; +} + +List *reverseListWithStack(List *list) +{ + if (list == NULL) + return NULL; + Node *pTemp = list->pHead; + Stack *stack = new Stack; + int count = 0; + while (pTemp != NULL) + { + stack->push(pTemp->data); + pTemp = pTemp->next; + ++count; + } + List *ret = new List; + while (count > 0) + { + ret->addLast(stack->pop()); + --count; + } + return ret; +} + +List *reverseListWithQueue(List *list) +{ + if (list == NULL) + return NULL; + Node *pTemp = list->pHead; + Queue *queue = new Queue; + int count = 0; + while (pTemp != NULL) + { + queue->enQueue(pTemp->data); + pTemp = pTemp->next; + ++count; + } + List *ret = new List; + while (count > 0) + { + ret->addFirst(queue->deQueue()); + --count; + } + return ret; +} + +List *appendList(List *list1, List *list2) +{ + List *ret; + if (list2 == NULL) + { + ret = list1; + } + else if (list1 == NULL) + { + ret = list2; + } + else + { + Node *pTemp; + ret = new List; + pTemp = list1->pHead; + while (pTemp != NULL) + { + ret->addLast(pTemp->data); + pTemp = pTemp->next; + list1->removeFirst(); + } + pTemp = list2->pHead; + while (pTemp != NULL) + { + ret->addLast(pTemp->data); + pTemp = pTemp->next; + list2->removeFirst(); + } + } + delete list1; + list1 = NULL; + delete list2; + list2 = NULL; + return ret; +} diff --git a/Nhut/List.cpp b/Nhut/List.cpp new file mode 100644 index 0000000..8b6c81f --- /dev/null +++ b/Nhut/List.cpp @@ -0,0 +1,265 @@ +#include "List.h" +#include "Queue.h" +#include "Stack.h" + +List::List() +{ + pHead = NULL; + count = 0; +} + +void List::addLast(int newdata) +{ + Node *pNew = new Node; + pNew->data = newdata; + if (pHead == NULL) + { + pHead = pNew; + ++count; + return; + } + Node *pTemp = pHead; + while (pTemp->next != NULL) + { + pTemp = pTemp->next; + } + pTemp->next = pNew; + ++count; +} + +void List::addConstant(int nConstant) +{ + Node *pTemp = pHead; + if (pTemp == NULL) + return; + while (pTemp->next != NULL) + pTemp = pTemp->next; + pTemp->data += nConstant; + return; +} + +void List::addFirst(int newdata) +{ + Node *pTemp = new Node; + pTemp->data = newdata; + pTemp->next = pHead; + pHead = pTemp; + count++; +} + +void List::display() +{ + Node *pTemp = pHead; + while (pTemp != NULL) + { + cout << pTemp->data << " "; + pTemp = pTemp->next; + } + cout << endl; +} + +void List::displayPoly() +{ + Node *pTemp = pHead; + int i = 0; + while (pTemp != NULL) + { + int index = count - 1 - i; + if (pTemp->data != 0) + { + if (pTemp->data > 0) + { + if (i != 0) + cout << "+"; + } + cout << pTemp->data; + if (index == 1) + cout << "x"; + else if (index > 1) + cout << "x^" << index; + } + ++i; + pTemp = pTemp->next; + } + cout << endl; +} + +void List::removeFirst() +{ + if (pHead == NULL) + return; + Node *pDel = pHead; + pHead = pHead->next; + delete pDel; + --count; +} + +void List::removeLast() +{ + if (pHead == NULL) + return; + Node *pTemp = pHead; + if (count == 1) + { + pHead = NULL; + delete pTemp; + count = 0; + return; + } + Node *pPrev = NULL; + while (pTemp->next != NULL) + { + pPrev = pTemp; + pTemp = pTemp->next; + } + pPrev->next = NULL; + delete pTemp; + --count; +} + +int List::returnFirst() +{ + if (pHead == NULL) + return 0; + return pHead->data; +} + +int List::returnLast() +{ + if (pHead == NULL) + return 0; + Node *pTemp = pHead; + while (pTemp->next != NULL) + pTemp = pTemp->next; + return pTemp->data; +} + +List::~List() +{ + Node *pTemp = pHead; + while (pTemp != NULL) + { + pTemp = pTemp->next; + delete pHead; + pHead = pTemp; + } +} + +List *addPoly(List *list1, List *list2) +{ + if (list1 == NULL || list2 == NULL) + return NULL; + int i = list1->count, + j = list2->count; + Node *pHead1 = list1->pHead; + Node *pHead2 = list2->pHead; + if (i <= 0 || j <= 0) + return NULL; + if (i > j) + { + while (i > j) + { + pHead1 = pHead1->next; + --i; + } + } + else + { + while (j > i) + { + pHead2 = pHead2->next; + --j; + } + } + List *ret = new List; + while (i > 0) + { + int t = pHead1->data + pHead2->data; + ret->addLast(t); + pHead1 = pHead1->next; + pHead2 = pHead2->next; + --i; + } + return ret; +} + +List *reverseListWithStack(List *list) +{ + if (list == NULL) + return NULL; + Node *pTemp = list->pHead; + Stack *stack = new Stack; + int count = 0; + while (pTemp != NULL) + { + stack->push(pTemp->data); + pTemp = pTemp->next; + ++count; + } + List *ret = new List; + while (count > 0) + { + ret->addLast(stack->pop()); + --count; + } + return ret; +} + +List *reverseListWithQueue(List *list) +{ + if (list == NULL) + return NULL; + Node *pTemp = list->pHead; + Queue *queue = new Queue; + int count = 0; + while (pTemp != NULL) + { + queue->enQueue(pTemp->data); + pTemp = pTemp->next; + ++count; + } + List *ret = new List; + while (count > 0) + { + ret->addFirst(queue->deQueue()); + --count; + } + return ret; +} + +List *appendList(List *list1, List *list2) +{ + List *ret; + if (list2 == NULL) + { + ret = list1; + } + else if (list1 == NULL) + { + ret = list2; + } + else + { + Node *pTemp; + ret = new List; + pTemp = list1->pHead; + while (pTemp != NULL) + { + ret->addLast(pTemp->data); + pTemp = pTemp->next; + list1->removeFirst(); + } + pTemp = list2->pHead; + while (pTemp != NULL) + { + ret->addLast(pTemp->data); + pTemp = pTemp->next; + list2->removeFirst(); + } + } + delete list1; + list1 = NULL; + delete list2; + list2 = NULL; + return ret; +} diff --git a/Nhut/List.h b/Nhut/List.h new file mode 100644 index 0000000..6bffad1 --- /dev/null +++ b/Nhut/List.h @@ -0,0 +1,39 @@ +#ifndef LIST_H +#define LIST_H + +#include + +using namespace std; + +class Node +{ +public: + int data; + Node *next; +}; + +class List +{ +private: + int count; + Node *pHead; + +public: + List(); + void addLast(int); + void addConstant(int); + void addFirst(int); + void removeFirst(); + void removeLast(); + int returnFirst(); + int returnLast(); + void display(); + void displayPoly(); + friend List *addPoly(List *, List *); + friend List *reverseListWithStack(List *); + friend List *reverseListWithQueue(List *); + friend List *appendList(List *, List *); + ~List(); +}; + +#endif // LIST_H \ No newline at end of file diff --git a/Nhut/Poly.cpp b/Nhut/Poly.cpp new file mode 100644 index 0000000..5ab000f --- /dev/null +++ b/Nhut/Poly.cpp @@ -0,0 +1,41 @@ +#include "List.h" +#include "Queue.h" +#include "Stack.h" +#include + +using namespace std; + +int main() +{ + List *myList1 = new List, + *myList2 = new List; + myList1->addFirst(1); + myList1->addFirst(0); + myList1->addFirst(1); + myList1->addFirst(0); + myList1->addFirst(5); + myList1->display(); + myList2->addFirst(1); + myList2->addFirst(2); + myList2->addFirst(3); + myList2->display(); + myList1->displayPoly(); + myList2->displayPoly(); + List *result = addPoly(myList1, myList2); + myList1->display(); + myList2->display(); + if (result != NULL) + result->display(); + myList1->display(); + myList2->display(); + myList1->displayPoly(); + myList2->displayPoly(); + result->displayPoly(); + cout << myList1->returnFirst() << endl; + myList1->removeFirst(); + myList1->display(); + cout << myList1->returnLast() << endl; + myList1->removeLast(); + myList1->display(); + return 0; +} \ No newline at end of file diff --git a/Nhut/Queue.cpp b/Nhut/Queue.cpp new file mode 100644 index 0000000..afdddec --- /dev/null +++ b/Nhut/Queue.cpp @@ -0,0 +1,23 @@ +#include "Queue.h" + +Queue::Queue() +{ + queue = new List; +} + +void Queue::enQueue(int newdata) +{ + queue->addLast(newdata); +} + +int Queue::deQueue() +{ + int ret = queue->returnFirst(); + queue->removeFirst(); + return ret; +} + +Queue::~Queue() +{ + delete queue; +} \ No newline at end of file diff --git a/Nhut/Queue.h b/Nhut/Queue.h new file mode 100644 index 0000000..c41d82e --- /dev/null +++ b/Nhut/Queue.h @@ -0,0 +1,18 @@ +#ifndef QUEUE_H +#define QUEUE_H + +#include "List.h" + +class Queue +{ + private: + List *queue; + + public: + Queue(); + void enQueue(int); + int deQueue(); + ~Queue(); +}; + +#endif // QUEUE_H \ No newline at end of file diff --git a/Nhut/Stack.cpp b/Nhut/Stack.cpp new file mode 100644 index 0000000..a0b702e --- /dev/null +++ b/Nhut/Stack.cpp @@ -0,0 +1,23 @@ +#include "Stack.h" + +Stack::Stack() +{ + stack = new List; +} + +void Stack::push(int newdata) +{ + stack->addFirst(newdata); +} + +int Stack::pop() +{ + int ret = stack->returnFirst(); + stack->removeFirst(); + return ret; +} + +Stack::~Stack() +{ + delete stack; +} \ No newline at end of file diff --git a/Nhut/Stack.h b/Nhut/Stack.h new file mode 100644 index 0000000..447f69b --- /dev/null +++ b/Nhut/Stack.h @@ -0,0 +1,18 @@ +#ifndef STACK_H +#define STACK_H + +#include "List.h" + +class Stack +{ +private: + List *stack; + +public: + Stack(); + void push(int); + int pop(); + ~Stack(); +}; + +#endif // STACK_H \ No newline at end of file diff --git a/Poly b/Poly new file mode 100644 index 0000000000000000000000000000000000000000..76f4e66b56731e9f7c61a630382f908afd57f0b0 GIT binary patch literal 19392 zcmeHPeRNyJl^@A=;(TB$As=qCB!UKNAQp0P64OwSV=Ixt32tncBw(HuONmu%$+ez> zokP-qfufp^z;fEO`$4wbc6YmNNxLkYw!2OsDTdvgT^CYFmjZ4ZTDhjIDS>(^;Qig1 zJ5Nut1RVD4KYKhr(w+M`ckbMo_cZT~KkskY;B+{IE>3ZkAj~_hE zC49my&J#00DZhL;>4mMZKlEU*>1Db z2aIqZ0Z}Kv(~xATG`?bnsO~P4D4K{A8LH@vL=(Lgz13?f)>L`oG0!U5Z?aFa8#lMemUJB5z{uwX_)w^ce|9)E zaX1J%eGZ>GDU;W zo3nj$lUW^!#f=@oc(|%Q8ZqlC{kw$$daN_5wp+O z?S)jRvyp_G%&KrS)LGx&WL8$TcLaM3vnLoaXSJx^ zy0vC~y;148T#>hKg-8`fRxJ`vzydj|2`8*bemgPa9r$ZPZs_^ecv0URTFJix8WrMq z+xUqkky*4t{FTLbLPF`2{IieTjLSfw_zvrs7e9!l*C~#${KRE#BqrAmU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iZjdm+~+c<2uT+!D?^cZcW1DVdO+RDJ~qi}d|r|wp@y6zp^U(7 zGtm=m2%@X<04m!?|7&AW1U;%kkUpO|#cZyltXVF<-zixfWBmxHO|u)g4pSx+i5iJ` z7>T1ty{bDA?~uXfG~i>lmEK@?H_pz|VA%$r+{}Go*9Zm8pgNL@KsRry)rn4raOuoz zmOnfTRdYrt9y2;HdFfEF8YN0lp6)y>EV?5e*UhjEN>VvIlrucJGm?32D6Eo7j-N_* zPH-h&S*ZqDC3Jd}wNS>HO|;@ebh$^+jP%L9<73Xa&JSpMeSNo(6D%rtHOf|Wfv}f`qKNqfwX^sTLAnPRz>fZ z>Ho`-y>mgb_VRHcv=^%No1H#j>HmA-mRR}=w-p(M?yK$krqd_+CL3HKvGiBAejQkN zr7x!2Kj`#H;e$-5l305GxR`MbHls2JAFZ$V^M;vlm^+Ny9vLUCulIF713G?MSo(V3 zZ$CS#_oE>qOLqL|{)zU2b^CgMknXdn=>Fq2P!=tx;mx4Z-m=E^KB7Dk4PLiW6J(D3 z)c!MB(Ebj&s`d4L<7sZ+%YwRnt*`rk2kWnAIlVt#%p2rx?l9@o9#*#geV~yDH)ri% zmb2gz@a%=dYLSwt+4c24XCvzmTav2cVqC+Avh>}&kLI4G1hv1cX8Eu2zsSw7*8h?!Vq&E#v^R87(fy%0f{2JJ#3Zr+?qNSYJPv(K^}j`(Bp5oA*of z|DVzSXC|Ni(JXzvuiHq2jj~cFjzXuz?`hDf|Jr}O|9k5)rO?WH8j!5Lya0qkOu0=( z? + +using namespace std; + +int main() +{ + List *myList1 = new List, + *myList2 = new List; + myList1->addFirst(1); + myList1->addFirst(0); + myList1->addFirst(1); + myList1->addFirst(0); + myList1->addFirst(5); + myList1->display(); + myList2->addFirst(1); + myList2->addFirst(2); + myList2->addFirst(3); + myList2->display(); + myList1->displayPoly(); + myList2->displayPoly(); + List *result = addPoly(myList1, myList2); + myList1->display(); + myList2->display(); + if (result != NULL) + result->display(); + myList1->display(); + myList2->display(); + myList1->displayPoly(); + myList2->displayPoly(); + result->displayPoly(); + cout << myList1->returnFirst() << endl; + myList1->removeFirst(); + myList1->display(); + cout << myList1->returnLast() << endl; + myList1->removeLast(); + myList1->display(); + return 0; +} \ No newline at end of file diff --git a/Queue.cpp b/Queue.cpp new file mode 100644 index 0000000..afdddec --- /dev/null +++ b/Queue.cpp @@ -0,0 +1,23 @@ +#include "Queue.h" + +Queue::Queue() +{ + queue = new List; +} + +void Queue::enQueue(int newdata) +{ + queue->addLast(newdata); +} + +int Queue::deQueue() +{ + int ret = queue->returnFirst(); + queue->removeFirst(); + return ret; +} + +Queue::~Queue() +{ + delete queue; +} \ No newline at end of file diff --git a/Queue.h b/Queue.h new file mode 100644 index 0000000..c41d82e --- /dev/null +++ b/Queue.h @@ -0,0 +1,18 @@ +#ifndef QUEUE_H +#define QUEUE_H + +#include "List.h" + +class Queue +{ + private: + List *queue; + + public: + Queue(); + void enQueue(int); + int deQueue(); + ~Queue(); +}; + +#endif // QUEUE_H \ No newline at end of file diff --git a/Stack.cpp b/Stack.cpp new file mode 100644 index 0000000..a0b702e --- /dev/null +++ b/Stack.cpp @@ -0,0 +1,23 @@ +#include "Stack.h" + +Stack::Stack() +{ + stack = new List; +} + +void Stack::push(int newdata) +{ + stack->addFirst(newdata); +} + +int Stack::pop() +{ + int ret = stack->returnFirst(); + stack->removeFirst(); + return ret; +} + +Stack::~Stack() +{ + delete stack; +} \ No newline at end of file diff --git a/Stack.h b/Stack.h new file mode 100644 index 0000000..447f69b --- /dev/null +++ b/Stack.h @@ -0,0 +1,18 @@ +#ifndef STACK_H +#define STACK_H + +#include "List.h" + +class Stack +{ +private: + List *stack; + +public: + Stack(); + void push(int); + int pop(); + ~Stack(); +}; + +#endif // STACK_H \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..a581680 --- /dev/null +++ b/makefile @@ -0,0 +1,12 @@ +all: List.o Queue.o Stack.o Poly.o + g++ -o Poly List.o Queue.o Stack.o Poly.o +List.o: List.h List.cpp + g++ -c List.h List.cpp +Queue.o: Queue.h Queue.cpp + g++ -c Queue.h Queue.cpp +Stack.o: Stack.h Stack.cpp + g++ -c Stack.h Stack.cpp +Poly.o: Poly.cpp + g++ -c Poly.cpp +clean: + rm -f *.o Poly