├── Week4 ├── bin │ └── readme ├── lib │ └── readme ├── readme ├── src │ ├── Exception.cpp │ └── Test.cpp ├── include │ ├── EmptyList.hpp │ ├── NoSuchElement.hpp │ ├── IndexOutOfBound.hpp │ ├── Exception.hpp │ └── ArrayList.hpp └── makefile ├── Week10 ├── BST │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── makefile │ ├── src │ │ └── Test.cpp │ └── include │ │ └── BST.hpp └── readme ├── Week11 ├── AVL │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── makefile │ ├── src │ │ └── Test.cpp │ └── include │ │ └── AVL.hpp └── readme ├── Week7 ├── Stack │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── makefile │ ├── src │ │ ├── Test.cpp │ │ └── Postfix.cpp │ └── include │ │ ├── Postfix.hpp │ │ └── Stack.hpp ├── Labirent │ ├── bin │ │ └── README.md │ ├── lib │ │ └── README.md │ ├── README.md │ ├── makefile │ ├── include │ │ ├── Konum.hpp │ │ ├── Labirent.hpp │ │ └── Stack.hpp │ ├── Harita.txt │ └── src │ │ ├── Konum.cpp │ │ ├── Test.cpp │ │ └── Labirent.cpp ├── BaseConverter │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── README.md │ ├── src │ │ ├── Test.cpp │ │ └── BaseConverter.cpp │ ├── makefile │ └── include │ │ ├── BaseConverter.hpp │ │ └── Stack.hpp ├── CheckParentheses │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── README.md │ ├── makefile │ ├── include │ │ ├── Text.hpp │ │ └── Stack.hpp │ └── src │ │ ├── Test.cpp │ │ └── Text.cpp └── readme ├── Week8 ├── Queue │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── makefile │ ├── include │ │ ├── Person.hpp │ │ └── Queue.hpp │ └── src │ │ ├── Person.cpp │ │ └── Test.cpp ├── RadixSort │ ├── bin │ │ └── README.md │ ├── lib │ │ └── README.md │ ├── README.md │ ├── makefile │ ├── include │ │ ├── Radix.hpp │ │ └── Queue.hpp │ └── src │ │ ├── Test.cpp │ │ └── Radix.cpp └── README.md ├── Odev2OrnekCiktilar ├── README.md ├── Balik.png ├── gulen_yuz.png ├── Balik_mutasyon.png └── gulen_yuz_mutasyon.png ├── Week12 ├── HeapTree │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── makefile │ ├── src │ │ ├── Test.cpp │ │ └── HeapTree.cpp │ └── include │ │ └── HeapTree.hpp └── readme ├── Week13 ├── Huffman │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── Data.txt │ ├── src │ │ ├── Test.cpp │ │ ├── Node.cpp │ │ └── Huffman.cpp │ ├── makefile │ └── include │ │ ├── Node.hpp │ │ └── Huffman.hpp └── README.md ├── Week14 ├── OpenHashing │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── makefile │ ├── src │ │ ├── Test.cpp │ │ └── Hash.cpp │ └── include │ │ └── Hash.hpp ├── DoubleHashing │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── makefile │ ├── src │ │ ├── Test.cpp │ │ └── DoubleHashing.cpp │ └── include │ │ └── DoubleHashing.hpp └── README.md ├── Week5 ├── LinkedList │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── makefile │ ├── include │ │ ├── Node.hpp │ │ ├── Iterator.hpp │ │ └── LinkedList.hpp │ └── src │ │ └── Test.cpp ├── CircularLinkedList │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── src │ │ ├── Exception.cpp │ │ └── Test.cpp │ ├── makefile │ └── include │ │ ├── NoSuchElement.hpp │ │ ├── Exception.hpp │ │ ├── Node.hpp │ │ ├── Iterator.hpp │ │ └── CircularLinkedList.hpp ├── readme ├── LinkedListv2 │ ├── Node.hpp │ ├── Test.cpp │ └── LinkedList.hpp └── LinkedListIterator │ ├── Node.hpp │ ├── Test.cpp │ ├── Esya.hpp │ ├── Iterator.hpp │ └── LinkedList.hpp ├── Week9 ├── ArrayBSTTree │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── makefile │ ├── src │ │ └── Test.cpp │ └── include │ │ └── BST.hpp └── readme ├── Week1 ├── Sample1 │ ├── lib │ │ └── readme │ ├── bin │ │ └── readme │ ├── makefile │ ├── include │ │ └── Ogrenci.hpp │ └── src │ │ ├── Ogrenci.cpp │ │ └── Test.cpp ├── Sample2 │ ├── lib │ │ └── readme │ ├── bin │ │ └── readme │ ├── src │ │ ├── Meyve.cpp │ │ ├── Sebze.cpp │ │ └── Test.cpp │ ├── include │ │ ├── Meyve.hpp │ │ ├── Sebze.hpp │ │ └── Ogrenci.hpp │ └── makefile ├── README.md └── GenericSamples │ ├── SablonOlmayanOrnek2.cpp │ ├── SablonOrnek2.cpp │ ├── SablonOrnek1.cpp │ └── SablonOlmayanOrnek1.cpp ├── Week2 ├── Sample2 │ ├── lib │ │ └── readme │ ├── bin │ │ └── readme │ ├── makefile │ ├── include │ │ ├── Kisi.hpp │ │ └── Sayi.hpp │ └── src │ │ ├── Kisi.cpp │ │ ├── Sayi.cpp │ │ └── Test.cpp ├── readme └── Sample1 │ ├── EqualityCheck.cpp │ ├── DoublePointer.cpp │ ├── DanglingPointer.cpp │ └── ClassPointer.cpp ├── Week6 ├── DoublyLinkedList │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── src │ │ ├── Exception.cpp │ │ └── Test.cpp │ ├── makefile │ └── include │ │ ├── NoSuchElement.hpp │ │ ├── Exception.hpp │ │ ├── Node.hpp │ │ └── DoublyLinkedList.hpp ├── CircularDoublyLinkedList │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── src │ │ ├── Exception.cpp │ │ └── Test.cpp │ ├── makefile │ └── include │ │ ├── NoSuchElement.hpp │ │ ├── Exception.hpp │ │ ├── Node.hpp │ │ └── CircularDoublyLinkedList.hpp └── readme ├── Week3 ├── readme ├── Sample1.cpp ├── Sample2.cpp ├── DiziTersCevir.cpp ├── HanoiKuleleri.cpp ├── Sample3.cpp ├── ikiliarama.cpp └── Sample4.cpp └── README.md /Week4/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week4/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week10/BST/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week10/BST/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week11/AVL/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week11/AVL/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week7/Stack/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week7/Stack/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week8/Queue/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week8/Queue/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Odev2OrnekCiktilar/README.md: -------------------------------------------------------------------------------- 1 | 2. Ödev Örnek Çıktılar 2 | -------------------------------------------------------------------------------- /Week12/HeapTree/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week12/HeapTree/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week13/Huffman/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week13/Huffman/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week14/OpenHashing/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week14/OpenHashing/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week5/LinkedList/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week5/LinkedList/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week7/Labirent/bin/README.md: -------------------------------------------------------------------------------- 1 | This folder is left blank 2 | -------------------------------------------------------------------------------- /Week7/Labirent/lib/README.md: -------------------------------------------------------------------------------- 1 | This folder is left blank 2 | -------------------------------------------------------------------------------- /Week9/ArrayBSTTree/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week9/ArrayBSTTree/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week1/Sample1/lib/readme: -------------------------------------------------------------------------------- 1 | This folder is for object files. 2 | -------------------------------------------------------------------------------- /Week1/Sample2/lib/readme: -------------------------------------------------------------------------------- 1 | This folder is for object files 2 | -------------------------------------------------------------------------------- /Week14/DoubleHashing/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week14/DoubleHashing/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week2/Sample2/lib/readme: -------------------------------------------------------------------------------- 1 | This folder is for object files. 2 | -------------------------------------------------------------------------------- /Week6/DoublyLinkedList/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week6/DoublyLinkedList/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week7/BaseConverter/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week7/BaseConverter/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week7/CheckParentheses/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week7/CheckParentheses/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week1/Sample1/bin/readme: -------------------------------------------------------------------------------- 1 | This folder is for executable files. 2 | -------------------------------------------------------------------------------- /Week2/Sample2/bin/readme: -------------------------------------------------------------------------------- 1 | This folder is for executable files 2 | -------------------------------------------------------------------------------- /Week5/CircularLinkedList/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week5/CircularLinkedList/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week8/RadixSort/bin/README.md: -------------------------------------------------------------------------------- 1 |

This folder left empty

2 | -------------------------------------------------------------------------------- /Week8/RadixSort/lib/README.md: -------------------------------------------------------------------------------- 1 |

This folder left empty

2 | -------------------------------------------------------------------------------- /Week1/Sample2/bin/readme: -------------------------------------------------------------------------------- 1 | This folder is for executable binary files. 2 | -------------------------------------------------------------------------------- /Week13/Huffman/Data.txt: -------------------------------------------------------------------------------- 1 | CCDDDDDAAAAAAAAAABBBBBBBBBBBBBBEEEEEEEEEEEE 2 | -------------------------------------------------------------------------------- /Week6/CircularDoublyLinkedList/bin/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week6/CircularDoublyLinkedList/lib/readme: -------------------------------------------------------------------------------- 1 | This file is left Empty. 2 | -------------------------------------------------------------------------------- /Week11/readme: -------------------------------------------------------------------------------- 1 | This week includes the implementation of the AVL tree. 2 | 3 | -------------------------------------------------------------------------------- /Week7/BaseConverter/README.md: -------------------------------------------------------------------------------- 1 |

Number Base Converter Using Stack

2 | -------------------------------------------------------------------------------- /Week7/CheckParentheses/README.md: -------------------------------------------------------------------------------- 1 |

Parantheses matching using Stack

2 | -------------------------------------------------------------------------------- /Week2/readme: -------------------------------------------------------------------------------- 1 | This week contains titles about Memory management and pointers. 2 | -------------------------------------------------------------------------------- /Week5/readme: -------------------------------------------------------------------------------- 1 | This week contains titles about LinkedList, Circular LinkedList. 2 | -------------------------------------------------------------------------------- /Week7/readme: -------------------------------------------------------------------------------- 1 | This week includes stack implementation and stack applications. 2 | -------------------------------------------------------------------------------- /Week12/readme: -------------------------------------------------------------------------------- 1 | This week includes the implementation of the heapsort by heap tree. 2 | -------------------------------------------------------------------------------- /Week10/readme: -------------------------------------------------------------------------------- 1 | This week includes the implementation of the linked binary search tree. 2 | -------------------------------------------------------------------------------- /Week6/readme: -------------------------------------------------------------------------------- 1 | This week contains titles about Doubly LinkedList and Doubly Circular LinkedList. 2 | -------------------------------------------------------------------------------- /Week9/readme: -------------------------------------------------------------------------------- 1 | This week includes the implementation of the binary search tree on the array. 2 | -------------------------------------------------------------------------------- /Week4/readme: -------------------------------------------------------------------------------- 1 | This week contains titles about implementing List data structure by array (ArrayList). 2 | -------------------------------------------------------------------------------- /Odev2OrnekCiktilar/Balik.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfadak/DataStructures/HEAD/Odev2OrnekCiktilar/Balik.png -------------------------------------------------------------------------------- /Week3/readme: -------------------------------------------------------------------------------- 1 | This week contains titles about Array data structure, concept of recursion, Recursive algorithms. 2 | -------------------------------------------------------------------------------- /Odev2OrnekCiktilar/gulen_yuz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfadak/DataStructures/HEAD/Odev2OrnekCiktilar/gulen_yuz.png -------------------------------------------------------------------------------- /Week4/src/Exception.cpp: -------------------------------------------------------------------------------- 1 | #include "Exception.hpp" 2 | 3 | string Exception::Message()const{ 4 | return message; 5 | } 6 | -------------------------------------------------------------------------------- /Odev2OrnekCiktilar/Balik_mutasyon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfadak/DataStructures/HEAD/Odev2OrnekCiktilar/Balik_mutasyon.png -------------------------------------------------------------------------------- /Week13/README.md: -------------------------------------------------------------------------------- 1 |

Data Compression

2 | This week includes the implementation of the Huffman Coding by binary tree. 3 | -------------------------------------------------------------------------------- /Odev2OrnekCiktilar/gulen_yuz_mutasyon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfadak/DataStructures/HEAD/Odev2OrnekCiktilar/gulen_yuz_mutasyon.png -------------------------------------------------------------------------------- /Week10/BST/makefile: -------------------------------------------------------------------------------- 1 | all: compile run 2 | 3 | compile: 4 | g++ -I ./include/ -o ./bin/Test ./src/Test.cpp 5 | 6 | run: 7 | ./bin/Test 8 | -------------------------------------------------------------------------------- /Week11/AVL/makefile: -------------------------------------------------------------------------------- 1 | all: compile run 2 | 3 | compile: 4 | g++ -I ./include/ -o ./bin/Test ./src/Test.cpp 5 | 6 | run: 7 | ./bin/Test 8 | -------------------------------------------------------------------------------- /Week5/CircularLinkedList/src/Exception.cpp: -------------------------------------------------------------------------------- 1 | #include "Exception.hpp" 2 | 3 | string Exception::Message()const{ 4 | return message; 5 | } 6 | -------------------------------------------------------------------------------- /Week6/DoublyLinkedList/src/Exception.cpp: -------------------------------------------------------------------------------- 1 | #include "Exception.hpp" 2 | 3 | string Exception::Message()const{ 4 | return message; 5 | } 6 | -------------------------------------------------------------------------------- /Week8/RadixSort/README.md: -------------------------------------------------------------------------------- 1 |

Radix Sort implementation with Queue

2 | 3 | Video Link: Go 4 | -------------------------------------------------------------------------------- /Week6/CircularDoublyLinkedList/src/Exception.cpp: -------------------------------------------------------------------------------- 1 | #include "Exception.hpp" 2 | 3 | string Exception::Message()const{ 4 | return message; 5 | } 6 | -------------------------------------------------------------------------------- /Week8/README.md: -------------------------------------------------------------------------------- 1 | This week includes queue and Priority queue implementation. 2 | 3 | Video Link: Go 4 | -------------------------------------------------------------------------------- /Week1/README.md: -------------------------------------------------------------------------------- 1 | This week contains titles about basic data types, data concept and algorithm analysis.

2 | 3 | https://youtu.be/H4b5eCoc7VM 4 | -------------------------------------------------------------------------------- /Week7/Labirent/README.md: -------------------------------------------------------------------------------- 1 |

Labirentten Çıkış Probleminin Yığıt ile Çözümü

2 | 3 | Anlatım Videosu 4 | -------------------------------------------------------------------------------- /Week9/ArrayBSTTree/makefile: -------------------------------------------------------------------------------- 1 | all: compile run 2 | 3 | compile: 4 | g++ -I ./include/ -o ./bin/Test ./src/Test.cpp 5 | 6 | run: 7 | ./bin/Test 8 | -------------------------------------------------------------------------------- /Week5/LinkedList/makefile: -------------------------------------------------------------------------------- 1 | hepsi: derle calistir 2 | 3 | derle: 4 | g++ -I ./include/ -o ./bin/Test ./src/Test.cpp 5 | 6 | calistir: 7 | ./bin/Test 8 | -------------------------------------------------------------------------------- /Week6/CircularDoublyLinkedList/makefile: -------------------------------------------------------------------------------- 1 | all: compile run 2 | 3 | compile: 4 | g++ -I ./include/ -o ./bin/Test ./src/Test.cpp 5 | 6 | run: 7 | ./bin/Test 8 | -------------------------------------------------------------------------------- /Week6/DoublyLinkedList/makefile: -------------------------------------------------------------------------------- 1 | hepsi: derle calistir 2 | 3 | derle: 4 | g++ -I ./include/ -o ./bin/Test ./src/Test.cpp 5 | 6 | calistir: 7 | ./bin/Test 8 | -------------------------------------------------------------------------------- /Week14/README.md: -------------------------------------------------------------------------------- 1 |

Hashing

2 | This week includes the implementation of;
3 | 7 | -------------------------------------------------------------------------------- /Week1/Sample2/src/Meyve.cpp: -------------------------------------------------------------------------------- 1 | #include "Meyve.hpp" 2 | 3 | Meyve::Meyve(double kl){ 4 | kalori = kl; 5 | } 6 | double Meyve::getKalori()const{ 7 | return kalori; 8 | } 9 | -------------------------------------------------------------------------------- /Week7/BaseConverter/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseConverter.hpp" 2 | 3 | int main(){ 4 | BaseConverter *bc = new BaseConverter(); 5 | cout<<*bc; 6 | delete bc; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Week1/Sample2/src/Sebze.cpp: -------------------------------------------------------------------------------- 1 | #include "Sebze.hpp" 2 | 3 | Sebze::Sebze(double kalori){ 4 | this->kalori = kalori; 5 | } 6 | double Sebze::getKalori()const{ 7 | return this->kalori; 8 | } 9 | -------------------------------------------------------------------------------- /Week13/Huffman/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Huffman.hpp" 2 | 3 | int main(){ 4 | Huffman *huffman = new Huffman("Data.txt"); 5 | huffman->Encode(); 6 | cout<<*huffman<Add(arr[i]); 8 | } 9 | hash->Print(); 10 | delete hash; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Week7/CheckParentheses/include/Text.hpp: -------------------------------------------------------------------------------- 1 | #include "Stack.hpp" 2 | #include 3 | class Text{ 4 | private: 5 | string content; 6 | Stack *stack; 7 | 8 | public: 9 | Text(string); 10 | bool CheckParentheses(); 11 | ~Text(); 12 | }; 13 | -------------------------------------------------------------------------------- /Week4/include/NoSuchElement.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NOSUCHELEMENT_HPP 2 | #define NOSUCHELEMENT_HPP 3 | 4 | #include "Exception.hpp" 5 | 6 | class NoSuchElement : public Exception{ 7 | public: 8 | NoSuchElement(const string &msg):Exception(msg) { } 9 | }; 10 | #endif 11 | -------------------------------------------------------------------------------- /Week4/include/IndexOutOfBound.hpp: -------------------------------------------------------------------------------- 1 | #ifndef INDEXOUTOFBOUND_HPP 2 | #define INDEXOUTOFBOUND_HPP 3 | 4 | #include "Exception.hpp" 5 | 6 | class IndexOutOfBound : public Exception{ 7 | public: 8 | IndexOutOfBound(const string &msg):Exception(msg) { } 9 | }; 10 | #endif 11 | -------------------------------------------------------------------------------- /Week1/Sample2/makefile: -------------------------------------------------------------------------------- 1 | hepsi: derle calistir 2 | derle: 3 | g++ -I ./include/ -o ./lib/Sebze.o -c ./src/Sebze.cpp 4 | g++ -I ./include/ -o ./lib/Meyve.o -c ./src/Meyve.cpp 5 | g++ -I ./include/ -o ./bin/Test ./lib/Sebze.o ./lib/Meyve.o ./src/Test.cpp 6 | 7 | calistir: 8 | ./bin/Test 9 | -------------------------------------------------------------------------------- /Week5/CircularLinkedList/include/NoSuchElement.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NOSUCHELEMENT_HPP 2 | #define NOSUCHELEMENT_HPP 3 | 4 | #include "Exception.hpp" 5 | 6 | class NoSuchElement : public Exception{ 7 | public: 8 | NoSuchElement(const string &msg):Exception(msg) { } 9 | }; 10 | #endif 11 | -------------------------------------------------------------------------------- /Week6/DoublyLinkedList/include/NoSuchElement.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NOSUCHELEMENT_HPP 2 | #define NOSUCHELEMENT_HPP 3 | 4 | #include "Exception.hpp" 5 | 6 | class NoSuchElement : public Exception{ 7 | public: 8 | NoSuchElement(const string &msg):Exception(msg) { } 9 | }; 10 | #endif 11 | -------------------------------------------------------------------------------- /Week14/DoubleHashing/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "DoubleHashing.hpp" 2 | 3 | int main(){ 4 | int arr[]={20, 5, 13, 0, 7}; 5 | DoubleHashing *hash = new DoubleHashing(7); 6 | for(int i=0;i<5;i++){ 7 | hash->Add(arr[i]); 8 | } 9 | hash->Print(); 10 | delete hash; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Week6/CircularDoublyLinkedList/include/NoSuchElement.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NOSUCHELEMENT_HPP 2 | #define NOSUCHELEMENT_HPP 3 | 4 | #include "Exception.hpp" 5 | 6 | class NoSuchElement : public Exception{ 7 | public: 8 | NoSuchElement(const string &msg):Exception(msg) { } 9 | }; 10 | #endif 11 | -------------------------------------------------------------------------------- /Week13/Huffman/makefile: -------------------------------------------------------------------------------- 1 | all: compile run 2 | 3 | compile: 4 | g++ -I ./include/ -o ./lib/Node.o -c ./src/Node.cpp 5 | g++ -I ./include/ -o ./lib/Huffman.o -c ./src/Huffman.cpp 6 | g++ -I ./include/ -o ./bin/Test ./lib/Node.o ./lib/Huffman.o ./src/Test.cpp 7 | 8 | run: 9 | ./bin/Test 10 | -------------------------------------------------------------------------------- /Week2/Sample2/makefile: -------------------------------------------------------------------------------- 1 | hepsi: derle calistir 2 | 3 | derle: 4 | g++ -I ./include/ -o ./lib/Sayi.o -c ./src/Sayi.cpp 5 | g++ -I ./include/ -o ./lib/Kisi.o -c ./src/Kisi.cpp 6 | g++ -I ./include/ -o ./bin/Test ./lib/Sayi.o ./lib/Kisi.o ./src/Test.cpp 7 | 8 | calistir: 9 | ./bin/Test 10 | 11 | -------------------------------------------------------------------------------- /Week2/Sample2/include/Kisi.hpp: -------------------------------------------------------------------------------- 1 | #ifndef KISI_HPP 2 | #define KISI_HPP 3 | 4 | #include "Sayi.hpp" 5 | 6 | class Kisi{ 7 | private: 8 | string isim; 9 | public: 10 | Sayi *yas; 11 | Kisi(string,int); 12 | friend ostream& operator<<(ostream&,Kisi&); 13 | ~Kisi(); 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /Week7/Labirent/makefile: -------------------------------------------------------------------------------- 1 | hepsi: derle calistir 2 | 3 | derle: 4 | g++ -I ./include/ -o ./lib/Konum.o -c ./src/Konum.cpp 5 | g++ -I ./include/ -o ./lib/Labirent.o -c ./src/Labirent.cpp 6 | g++ -I ./include/ -o ./bin/Test ./lib/Konum.o ./lib/Labirent.o ./src/Test.cpp 7 | 8 | calistir: 9 | ./bin/Test 10 | -------------------------------------------------------------------------------- /Week2/Sample2/src/Kisi.cpp: -------------------------------------------------------------------------------- 1 | #include "Kisi.hpp" 2 | 3 | Kisi::Kisi(string isim,int ys){ 4 | this->isim = isim; 5 | yas = new Sayi(ys); 6 | } 7 | Kisi::~Kisi(){ 8 | delete yas; 9 | } 10 | ostream& operator<<(ostream& ekran,Kisi& sag){ 11 | ekran< 5 | using namespace std; 6 | 7 | class Exception{ 8 | private: 9 | string message; 10 | public: 11 | Exception(const string &msg):message(msg) { } 12 | string Message()const; 13 | }; 14 | #endif 15 | -------------------------------------------------------------------------------- /Week2/Sample2/include/Sayi.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SAYI_HPP 2 | #define SAYI_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | class Sayi{ 8 | private: 9 | int *pdeger; 10 | public: 11 | Sayi(int); 12 | Sayi(); 13 | friend ostream& operator<<(ostream&,Sayi&); 14 | ~Sayi(); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Week2/Sample2/src/Sayi.cpp: -------------------------------------------------------------------------------- 1 | #include "Sayi.hpp" 2 | 3 | Sayi::Sayi(int dgr){ 4 | pdeger = new int(dgr); 5 | } 6 | Sayi::Sayi(){ 7 | pdeger = new int(0); 8 | } 9 | ostream& operator<<(ostream& ekran,Sayi& sag){ 10 | ekran<<*sag.pdeger<>infix; 7 | Postfix *postfix = new Postfix(infix); 8 | cout<<"Postfix: "<<*postfix<Calculate()< 5 | using namespace std; 6 | 7 | class Exception{ 8 | private: 9 | string message; 10 | public: 11 | Exception(const string &msg):message(msg) { } 12 | string Message()const; 13 | }; 14 | #endif 15 | -------------------------------------------------------------------------------- /Week6/DoublyLinkedList/include/Exception.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPTION_HPP 2 | #define EXCEPTION_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | class Exception{ 8 | private: 9 | string message; 10 | public: 11 | Exception(const string &msg):message(msg) { } 12 | string Message()const; 13 | }; 14 | #endif 15 | -------------------------------------------------------------------------------- /Week6/CircularDoublyLinkedList/include/Exception.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPTION_HPP 2 | #define EXCEPTION_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | class Exception{ 8 | private: 9 | string message; 10 | public: 11 | Exception(const string &msg):message(msg) { } 12 | string Message()const; 13 | }; 14 | #endif 15 | -------------------------------------------------------------------------------- /Week7/CheckParentheses/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Text.hpp" 2 | 3 | int main(){ 4 | string content; 5 | cout<<"Content: "; 6 | getline(cin,content); 7 | Text *text = new Text(content); 8 | if(text->CheckParentheses()) cout<<"Parentheses are match"; 9 | else cout<<"Parentheses are not match"; 10 | delete text; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Week8/RadixSort/include/Radix.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_HPP 2 | #define RADIX_HPP 3 | 4 | #include "Queue.hpp" 5 | 6 | class Radix{ 7 | private: 8 | int* numbers; 9 | int length; 10 | Queue **queues; 11 | 12 | int findMax(); 13 | public: 14 | Radix(int*, int); 15 | int* Sort(); 16 | ~Radix(); 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /Week8/Queue/include/Person.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PERSON_HPP 2 | #define PERSON_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | class Person{ 8 | public: 9 | string name; 10 | double weight; 11 | Person(); 12 | Person(string,double); 13 | friend ostream& operator<<(ostream&,Person&); 14 | bool operator>(Person&); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Week5/LinkedListv2/Node.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NODE_HPP 2 | #define NODE_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object item; 11 | Node *next; 12 | Node(const Object& item=Object(),Node *nx=NULL){ 13 | this->item=item; 14 | next=nx; 15 | } 16 | }; 17 | #endif 18 | -------------------------------------------------------------------------------- /Week5/LinkedListIterator/Node.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NODE_HPP 2 | #define NODE_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object item; 11 | Node *next; 12 | Node(const Object& item=Object(),Node *nx=NULL){ 13 | this->item=item; 14 | next=nx; 15 | } 16 | }; 17 | #endif 18 | -------------------------------------------------------------------------------- /Week3/Sample1.cpp: -------------------------------------------------------------------------------- 1 | int* DiziOlusturSifirla(int uzunluk){ 2 | int *sayilar = new int[uzunluk]; 3 | for(int i=0;i>uzunluk; 12 | int *p = DiziOlusturSifirla(uzunluk); 13 | cout<yas; 9 | ahmet->yas = mehmet->yas; 10 | mehmet->yas = yasYedek; 11 | cout<<*ahmet; 12 | cout<<*mehmet; 13 | delete ahmet; 14 | delete mehmet; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Week1/Sample1/include/Ogrenci.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OGRENCI_HPP 2 | #define OGRENCI_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | class Ogrenci{ 8 | private: 9 | int yas; 10 | double boy; 11 | public: 12 | Ogrenci(int,double); 13 | Ogrenci(); 14 | void YasIlerle(int); 15 | void BoyUza(double); 16 | int getYas(); 17 | double getBoy(); 18 | ~Ogrenci(); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Week5/LinkedList/include/Node.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NODE_HPP 2 | #define NODE_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object item; 11 | Node *next; 12 | 13 | Node(const Object& item=Object(),Node *next=NULL){ 14 | this->item = item; 15 | this->next = next; 16 | } 17 | 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Week3/Sample2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Kisi{ 4 | private: 5 | string isim; 6 | int yas; 7 | public: 8 | Kisi(string ism){ 9 | isim=ism; 10 | yas=0; 11 | } 12 | }; 13 | int main(){ 14 | Kisi **kisiler = new Kisi*[10]; 15 | for(int i=0;i<10;i++) kisiler[i] = new Kisi("Mehmet"); 16 | for(int i=0;i<10;i++) delete kisiler[i]; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Week5/CircularLinkedList/include/Node.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NODE_HPP 2 | #define NODE_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object item; 11 | Node *next; 12 | 13 | Node(const Object& item=Object(),Node *next=NULL){ 14 | this->item = item; 15 | this->next = next; 16 | } 17 | 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Week7/BaseConverter/include/BaseConverter.hpp: -------------------------------------------------------------------------------- 1 | #include "Stack.hpp" 2 | #include 3 | class BaseConverter{ 4 | private: 5 | int value; 6 | int base; 7 | string converted; 8 | 9 | string Convert(); 10 | public: 11 | BaseConverter(); 12 | int getValueBase10()const; 13 | friend ostream& operator<<(ostream&,BaseConverter&); 14 | friend istream& operator>>(istream&,BaseConverter&); 15 | }; 16 | -------------------------------------------------------------------------------- /Week7/Labirent/include/Konum.hpp: -------------------------------------------------------------------------------- 1 | #ifndef KONUM_HPP 2 | #define KONUM_HPP 3 | 4 | typedef enum{ ASAGI, SOL, YUKARI, SAG}Yon; 5 | 6 | 7 | struct Konum{ 8 | int x,y; 9 | Yon yon; 10 | Konum(int,int,Yon); 11 | Konum(int,int); 12 | Konum(); 13 | Konum AyniYon(); 14 | Konum SaatYonu(Yon); 15 | Konum Asagi(); 16 | Konum Yukari(); 17 | Konum Sol(); 18 | Konum Sag(); 19 | Yon TersYon(); 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Week3/DiziTersCevir.cpp: -------------------------------------------------------------------------------- 1 | void diziTersCevir(int dizi[],int uzunluk){ 2 | if(uzunluk > 1){ 3 | int tmp = dizi[0]; 4 | dizi[0] = dizi[uzunluk-1]; 5 | dizi[uzunluk-1] = tmp; 6 | 7 | diziTersCevir(dizi+1,uzunluk-2); 8 | } 9 | } 10 | 11 | int main(){ 12 | int sayilar[] = {27, 46, 17, 90, 63}; 13 | diziTersCevir(sayilar,5); 14 | for(int index=0;index<5;index++){ 15 | cout< 5 | using namespace std; 6 | 7 | struct Node{ 8 | char chracter; 9 | int freq; 10 | string code; 11 | 12 | Node *left; 13 | Node *right; 14 | 15 | Node(char ch,int frq,Node *lf=NULL,Node *rg=NULL); 16 | bool isLeaf()const; 17 | bool operator==(Node&); 18 | bool operator!=(Node&); 19 | bool operator>(Node&); 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Week2/Sample1/DoublePointer.cpp: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int a=50; 3 | int *p=&a; 4 | int **pp = &p; 5 | cout<<"pp nin adres: "<<&pp<name = name; 9 | this->weight = weight; 10 | } 11 | ostream& operator<<(ostream& screen,Person& rgt){ 12 | screen<(Person& rgt){ 16 | return this->weight > rgt.weight; 17 | } 18 | -------------------------------------------------------------------------------- /Week1/Sample1/src/Ogrenci.cpp: -------------------------------------------------------------------------------- 1 | #include "Ogrenci.hpp" 2 | 3 | Ogrenci::Ogrenci(int ys,double by){ 4 | yas=ys; 5 | boy=by; 6 | } 7 | Ogrenci::Ogrenci(){ 8 | yas=0; 9 | boy=30; 10 | } 11 | void Ogrenci::YasIlerle(int ys){ 12 | yas+=ys; 13 | } 14 | void Ogrenci::BoyUza(double by){ 15 | boy+=by; 16 | } 17 | int Ogrenci::getYas(){ 18 | return yas; 19 | } 20 | double Ogrenci::getBoy(){ 21 | return boy; 22 | } 23 | Ogrenci::~Ogrenci(){ 24 | cout<<"Cagrildi"< 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object data; 11 | Node *next; 12 | Node *prev; 13 | 14 | Node(const Object data,Node *next=NULL,Node *prev=NULL){ 15 | this->data = data; 16 | this->next = next; 17 | this->prev = prev; 18 | } 19 | }; 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Week6/CircularDoublyLinkedList/include/Node.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NODE_HPP 2 | #define NODE_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object data; 11 | Node *next; 12 | Node *prev; 13 | 14 | Node(const Object data,Node *next=NULL,Node *prev=NULL){ 15 | this->data = data; 16 | this->next = next; 17 | this->prev = prev; 18 | } 19 | }; 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Week10/BST/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "BST.hpp" 2 | 3 | int main(){ 4 | BST *bst = new BST(); 5 | bst->Add(105); 6 | bst->Add(67); 7 | bst->Add(223); 8 | bst->Add(197); 9 | bst->Add(54); 10 | bst->Add(47); 11 | bst->Add(90); 12 | bst->Add(546); 13 | bst->Add(571); 14 | bst->Add(320); 15 | bst->postorder(); 16 | cout<Height()<Search(95)) cout<<"Item found"<Sort(); 7 | cout<<"Siralanmadan Onceki Hali:"< *avl = new AVL(); 5 | avl->Add(105); 6 | avl->Add(67); 7 | avl->Add(223); 8 | avl->Add(197); 9 | avl->Add(54); 10 | avl->Add(47); 11 | avl->Add(90); 12 | avl->Add(546); 13 | avl->Add(571); 14 | avl->Add(320); 15 | avl->postorder(); 16 | cout<Height()<Search(95)) cout<<"Item found"<preorder(); 20 | delete avl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Week13/Huffman/src/Node.cpp: -------------------------------------------------------------------------------- 1 | #include "Node.hpp" 2 | 3 | Node::Node(char ch,int frq,Node *lf,Node *rg){ 4 | chracter = ch; 5 | freq = frq; 6 | left = lf; 7 | right = rg; 8 | code=""; 9 | } 10 | bool Node::isLeaf()const{ 11 | return left == NULL && right == NULL; 12 | } 13 | bool Node::operator==(Node& rgt){ 14 | return this->chracter == rgt.chracter; 15 | } 16 | bool Node::operator!=(Node& rgt){ 17 | return this->chracter == rgt.chracter; 18 | } 19 | bool Node::operator>(Node& rgt){ 20 | return this->freq > rgt.freq; 21 | } 22 | -------------------------------------------------------------------------------- /Week1/GenericSamples/SablonOlmayanOrnek2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Kutu{ 5 | public: 6 | int icerik; 7 | Kutu(int icerik){ 8 | this->icerik = icerik; 9 | } 10 | Kutu(){ 11 | this->icerik = int(); 12 | } 13 | friend ostream& operator<<(ostream& ekran,Kutu& sag){ 14 | ekran << sag.icerik; 15 | return ekran; 16 | } 17 | 18 | }; 19 | 20 | int main(){ 21 | int a=100; 22 | 23 | Kutu *kutu1 = new Kutu(a); 24 | cout<<*kutu1; 25 | 26 | delete kutu1; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Week12/HeapTree/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "HeapTree.hpp" 3 | 4 | int main(){ 5 | int *array = new int[25]; 6 | cout<<"Array before ordered:"<Sort(); 15 | cout< 3 | #include 4 | 5 | class Huffman{ 6 | private: 7 | Node* root; 8 | int symbols; 9 | string input; 10 | 11 | Node* CreateTree(int freq[]); 12 | void AssignCodes(Node*,string); 13 | int MinNodeIndex(Node* trees[]); 14 | void ReadFile(string); 15 | void inorder(Node*); 16 | void RemoveNode(Node*&); 17 | 18 | public: 19 | Huffman(string); 20 | void Encode(); 21 | friend ostream& operator<<(ostream&,Huffman&); 22 | ~Huffman(); 23 | }; 24 | -------------------------------------------------------------------------------- /Week8/Queue/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Queue.hpp" 2 | #include "Person.hpp" 3 | 4 | int main(){ 5 | Queue *group = new Queue(); 6 | Person *p1 = new Person("Mehmet",85); 7 | Person *p2 = new Person("Ceren",35); 8 | Person *p3 = new Person("Hamza",90); 9 | 10 | group->enqueue(*p1); 11 | group->enqueue(*p2); 12 | group->enqueue(*p3); 13 | 14 | group->dequeueMax(); 15 | 16 | cout<peek()<peekMax()< 2 | using namespace std; 3 | 4 | void Hanoi(int diskSayisi,char kaynak,char ara, char hedef){ 5 | if(diskSayisi == 1) 6 | cout<<"Diski "<>diskSayisi; 19 | Hanoi(diskSayisi,'A','B','C'); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Week14/DoubleHashing/include/DoubleHashing.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DOUBLEHASHING_HPP 2 | #define DOUBLEHASHING_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | class DoubleHashing{ 8 | private: 9 | int *Table; 10 | int size; 11 | int capacity; 12 | int R; 13 | 14 | int Hash1(int); 15 | int Hash2(int); 16 | bool isFull(); 17 | bool isPrime(int); 18 | public: 19 | DoubleHashing(int); 20 | void Add(int); 21 | bool Search(int); 22 | bool Remove(int); 23 | void Clear(); 24 | void Print(); 25 | ~DoubleHashing(); 26 | 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Week7/Stack/include/Postfix.hpp: -------------------------------------------------------------------------------- 1 | #ifndef POSTFIX_HPP 2 | #define POSTFIX_HPP 3 | 4 | #include "Stack.hpp" 5 | #include 6 | #include 7 | #include 8 | 9 | class Postfix{ 10 | private: 11 | string value; 12 | 13 | bool IsPriorityLow(char,char); 14 | void CopyPostfix(Stack*,string&); 15 | string infixToPostfix(string); 16 | double StringToDouble(string); 17 | 18 | public: 19 | Postfix(string); 20 | double Calculate(); 21 | string GetPostfixValue()const; 22 | friend ostream& operator<<(ostream&, Postfix&); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Week12/HeapTree/include/HeapTree.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HEAPTREE_HPP 2 | #define HEAPTREE_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | class HeapTree{ 8 | private: 9 | int *items; 10 | int length; 11 | int capacity; 12 | 13 | int LeftChildIndex(int); 14 | int RightChildIndex(int); 15 | int ParentIndex(int); 16 | void HeapfyUp(int); 17 | void HeapfyDown(int); 18 | void Swap(int&,int&); 19 | bool IsEmpty(); 20 | void Add(int); 21 | int RemoveMin(); 22 | public: 23 | HeapTree(int*,int); 24 | int* Sort(); 25 | ~HeapTree(); 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Week14/OpenHashing/include/Hash.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HASH_HPP 2 | #define HASH_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | struct Node{ 8 | int data; 9 | Node* next; 10 | 11 | Node(int dt,Node *nx=NULL){ 12 | this->data = dt; 13 | this->next = nx; 14 | } 15 | }; 16 | 17 | class Hash{ 18 | private: 19 | Node **Table; 20 | int capacity; 21 | int HashCode(int); 22 | public: 23 | Hash(int); 24 | void Add(int); 25 | bool Remove(int); 26 | void Clear(); 27 | bool Search(int); 28 | bool isEmpty(); 29 | void Print(); 30 | ~Hash(); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Week1/Sample2/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Ogrenci.hpp" 2 | #include "Sebze.hpp" 3 | #include "Meyve.hpp" 4 | 5 | int main(){ 6 | Ogrenci o1(5,135,52); 7 | 8 | cout<<"Ogrenci :"<(fasulye); 14 | Meyve kavun(2000); 15 | o1.YemekYe(kavun); 16 | cout<<"Ogrenci :"< 7 | class Iterator{ 8 | public: 9 | Node *current; 10 | Iterator(){ 11 | current = NULL; 12 | } 13 | Iterator(Node *current){ 14 | this->current = current; 15 | } 16 | bool hasNext(){ 17 | return current != NULL; 18 | } 19 | void next(){ 20 | // if(!hasNext()) throw hata 21 | current = current->next; 22 | } 23 | const Object& getCurrent()const{ 24 | // if(!hasNext()) throw hata 25 | return current->item; 26 | } 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Week5/LinkedListIterator/Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "LinkedList.hpp" 3 | #include "Esya.hpp" 4 | int main() 5 | { 6 | LinkedList *esyalar = new LinkedList(); 7 | esyalar->add(Esya("Masa",30,20)); 8 | esyalar->add(Esya("Sandalya",15,10)); 9 | esyalar->add(Esya("Kitap",2,5)); 10 | esyalar->add(Esya("Defter",1,5)); 11 | Iterator itr = esyalar->iterator(); 12 | 13 | double maksKilo; 14 | cout<<"Maks Kilo:"; 15 | cin>>maksKilo; 16 | 17 | while(itr.hasNext()){ 18 | Esya esya = itr.next(); 19 | if(esya.getKilo() > maksKilo) itr.remove(); 20 | } 21 | cout<<*esyalar; 22 | delete esyalar; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Week7/Labirent/include/Labirent.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LABIRENT_HPP 2 | #define LABIRENT_HPP 3 | 4 | #include 5 | #include 6 | #include "Windows.h" 7 | #include 8 | 9 | #include "Konum.hpp" 10 | #include "Stack.hpp" 11 | #define YUKSEKLIK 20 12 | #define GENISLIK 50 13 | 14 | class Labirent{ 15 | public: 16 | char harita[YUKSEKLIK][GENISLIK]; 17 | int x,y; 18 | Yon yon; 19 | Konum bitis; 20 | Stack *yigit; 21 | 22 | Labirent(Konum, Konum); 23 | Konum mevcutKonum(); 24 | bool adimAt(Konum, Konum); 25 | void ayarla(Konum,Yon); 26 | bool CikisaGeldimi(); 27 | bool EngelVarmi(Konum); 28 | string yaz(); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Week3/Sample3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Kisi{ 5 | private: 6 | string isim; 7 | int yas; 8 | public: 9 | Kisi(string isim,int yas){ 10 | this->isim = isim; 11 | this->yas = yas; 12 | } 13 | friend ostream& operator<<(ostream& ekran,Kisi& sag){ 14 | ekran< 2 | using namespace std; 3 | 4 | bool ikiliArama(int sayilar[],int baslangic,int bitis,int aranan){ 5 | int ortaindis = (baslangic+bitis) / 2; 6 | if(bitis < baslangic) return false; 7 | if(sayilar[ortaindis] == aranan) return true; 8 | if(aranan < sayilar[ortaindis]) 9 | return ikiliArama(sayilar, baslangic, ortaindis-1,aranan); 10 | if(aranan > sayilar[ortaindis]) 11 | return ikiliArama(sayilar, ortaindis+1, bitis,aranan); 12 | } 13 | 14 | int main(){ 15 | int dizi[]={17, 27, 46, 63, 90, 112, 125, 140, 157}; 16 | int x; 17 | cout<<"Aranan:"; 18 | cin>>x; 19 | if(ikiliArama(dizi,0,8,x)) cout<<"Sayi var"; 20 | else cout<<"Sayi yok"; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Week9/ArrayBSTTree/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "BST.hpp" 2 | 3 | int main(){ 4 | BST *tree = new BST(); 5 | 6 | tree->add(50); 7 | tree->add(40); 8 | tree->add(60); 9 | tree->add(30); 10 | tree->add(45); 11 | tree->add(55); 12 | tree->add(90); 13 | tree->add(15); 14 | tree->add(35); 15 | tree->add(42); 16 | tree->add(48); 17 | tree->add(54); 18 | tree->add(56); 19 | tree->add(70); 20 | tree->add(100); 21 | 22 | cout<<"Height: "<Height()<find(35)) cout<<"35 is exist"<find(500)) cout<<"500 is exist"<postorder(); 29 | tree->Delete(50); 30 | cout<inorder(); 32 | delete tree; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Week1/GenericSamples/SablonOrnek2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | class Kutu{ 6 | public: 7 | Tur icerik; 8 | Kutu(Tur icerik){ 9 | this->icerik = icerik; 10 | } 11 | Kutu(){ 12 | this->icerik = Tur(); 13 | } 14 | friend ostream& operator<<(ostream& ekran,Kutu& sag){ 15 | ekran << sag.icerik; 16 | return ekran; 17 | } 18 | 19 | }; 20 | 21 | int main(){ 22 | int a=100; 23 | 24 | Kutu *kutu1 = new Kutu(a); 25 | cout<<*kutu1< *kutu2 = new Kutu(str); 29 | cout<<*kutu2<> *kutu3 = new Kutu>(*kutu1); 32 | cout<<*kutu3< 5 | using namespace std; 6 | 7 | class Esya{ 8 | private: 9 | string isim; 10 | double hacim; 11 | double kilo; 12 | public: 13 | Esya(string isim, double kilo, double hacim){ 14 | this->isim = isim; 15 | this->hacim = hacim; 16 | this->kilo = kilo; 17 | } 18 | Esya(){ 19 | this->isim = ""; 20 | this->hacim = 0; 21 | this->kilo = 0; 22 | } 23 | double getKilo(){ 24 | return kilo; 25 | } 26 | bool operator!=(Esya &sag){ 27 | return this->isim != sag.isim; 28 | } 29 | bool operator==(Esya &sag){ 30 | return this->isim == sag.isim; 31 | } 32 | friend ostream& operator<<(ostream& ekran,Esya& sag){ 33 | ekran<<"\n"<content = content; 5 | stack = new Stack(); 6 | } 7 | bool Text::CheckParentheses(){ 8 | if (content == "") return true; 9 | 10 | for (int i = 0; i < content.length(); i++) 11 | { 12 | char current = content[i]; 13 | if (current == '{' || current == '(' || current == '[') 14 | { 15 | stack->push(current); 16 | } 17 | 18 | if (current == '}' || current == ')' || current == ']') 19 | { 20 | if (stack->isEmpty()) return false; 21 | 22 | char topParentheses = stack->top(); 23 | if (current == '}' && topParentheses == '{' || current == ')' && topParentheses == '(' || current == ']' && topParentheses == '[') 24 | stack->pop(); 25 | else 26 | return false; 27 | } 28 | 29 | } 30 | 31 | return stack->isEmpty(); 32 | } 33 | Text::~Text(){ 34 | delete stack; 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Data Structures 2 | It contains the codes I wrote in the data structures course. 3 | 4 | Week 1 : Basic data types, data concept and algorithm analysis.
5 | Week 2 : Memory management and pointers.
6 | Week 3 : Array data structure, concept of recursion, Recursive algorithms.
7 | Week 4 : List data structure using arrays (ArrayList).
8 | Week 5 : LinkedList, Circular LinkedList.
9 | Week 6 : Doubly LinkedList and Doubly Circular LinkedList.
10 | Week 7 : Stack implementation and Stack applications.
11 | Week 8 : Queue and Priority Queue Data Structures.
12 | Week 9 : Binary search tree implementations using array.
13 | Week 10 : Linked binary search tree.
14 | Week 11 : AVL Trees.
15 | Week 12 : Heap Tree.
16 | Week 13 : Huffman Tree.
17 | Week 14 : Hashing.
18 | -------------------------------------------------------------------------------- /Week1/Sample2/include/Ogrenci.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OGRENCI_HPP 2 | #define OGRENCI_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | class Ogrenci{ 8 | private: 9 | int yas; 10 | double boy; 11 | double kilo; 12 | public: 13 | Ogrenci(int ys,double by){ 14 | yas=ys; 15 | boy=by; 16 | } 17 | Ogrenci(){ 18 | yas=0; 19 | boy=30; 20 | } 21 | void YasIlerle(int ys){ 22 | yas+=ys; 23 | } 24 | void BoyUza(double by){ 25 | boy+=by; 26 | } 27 | int getYas(){ 28 | return yas; 29 | } 30 | double getBoy(){ 31 | return boy; 32 | } 33 | ~Ogrenci(){ 34 | cout<<"Cagrildi"< 45 | void YemekYe(YIYECEK yemek){ 46 | kilo += yemek.getKalori()/1000; 47 | } 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Week1/GenericSamples/SablonOrnek1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Sayi{ 5 | public: 6 | int deger; 7 | Sayi(int deger){ 8 | this->deger = deger; 9 | } 10 | Sayi(){ 11 | deger=0; 12 | } 13 | bool operator<(Sayi& sag){ 14 | return this->deger < sag.deger; 15 | } 16 | friend ostream& operator<<(ostream& ekran,Sayi& sag){ 17 | ekran << sag.deger; 18 | return ekran; 19 | } 20 | }; 21 | 22 | template 23 | Tur MinGetir(Tur& t1, Tur& t2){ 24 | return t1 < t2 ? t1 : t2; 25 | } 26 | 27 | int main(){ 28 | int a=10,b=21; 29 | cout<<"Min Tamsayi:"<(a,b)<(str1,str2)<(*sayi1,*sayi2)< *stack = new Stack(); 8 | 9 | while(vl > 0){ 10 | int remain = vl % base; 11 | stack->push(remain); 12 | vl = vl / base; 13 | } 14 | 15 | while(!stack->isEmpty()){ 16 | str = str + digits[stack->top()]; 17 | stack->pop(); 18 | } 19 | delete stack; 20 | return str; 21 | } 22 | BaseConverter::BaseConverter(){ 23 | cin>>*this; 24 | converted=Convert(); 25 | } 26 | int BaseConverter::getValueBase10()const{ 27 | return value; 28 | } 29 | ostream& operator<<(ostream& screen,BaseConverter &rgt){ 30 | screen<<"("<>(istream& in,BaseConverter &rgt){ 34 | cout<<"Value:"; 35 | in>>rgt.value; 36 | cout<<"Base:"; 37 | in>>rgt.base; 38 | return in; 39 | } 40 | -------------------------------------------------------------------------------- /Week5/LinkedList/include/Iterator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ITERATOR_HPP 2 | #define ITERATOR_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | #include "Node.hpp" 8 | 9 | template 10 | class Iterator{ 11 | private: 12 | Node *head; 13 | Node *current; 14 | Node *prev; 15 | 16 | public: 17 | Iterator(){ 18 | head=NULL; 19 | current=NULL; 20 | prev=NULL; 21 | } 22 | Iterator(Node *head){ 23 | this->current=head->next; 24 | this->head = head; 25 | prev=NULL; 26 | } 27 | bool hasNext(){ 28 | return current != NULL; 29 | } 30 | Object next(){ 31 | if(current == NULL) throw "NULL Reference"; 32 | prev=current; 33 | current = current->next; 34 | return prev->item; 35 | } 36 | void remove(){ 37 | if(prev == NULL) throw "NULL Reference"; 38 | Node *itr=head; 39 | for(;itr->next != prev;itr=itr->next){ } 40 | Node *del = itr->next; 41 | itr->next = itr->next->next; 42 | delete del; 43 | prev=NULL; 44 | } 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Week5/LinkedListIterator/Iterator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ITERATOR_HPP 2 | #define ITERATOR_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | #include "Node.hpp" 8 | 9 | template 10 | class Iterator{ 11 | private: 12 | Node *head; 13 | Node *current; 14 | Node *prev; 15 | 16 | public: 17 | Iterator(){ 18 | head=NULL; 19 | current=NULL; 20 | prev=NULL; 21 | } 22 | Iterator(Node *head){ 23 | this->current=head->next; 24 | this->head = head; 25 | prev=NULL; 26 | } 27 | bool hasNext(){ 28 | return current != NULL; 29 | } 30 | Object next(){ 31 | if(current == NULL) throw "NULL Reference"; 32 | prev=current; 33 | current = current->next; 34 | return prev->item; 35 | } 36 | void remove(){ 37 | if(prev == NULL) throw "NULL Reference"; 38 | Node *itr=head; 39 | for(;itr->next != prev;itr=itr->next){ } 40 | Node *del = itr->next; 41 | itr->next = itr->next->next; 42 | delete del; 43 | prev=NULL; 44 | } 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Week1/GenericSamples/SablonOlmayanOrnek1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Sayi{ 5 | public: 6 | int deger; 7 | Sayi(int deger){ 8 | this->deger = deger; 9 | } 10 | Sayi(){ 11 | deger=0; 12 | } 13 | bool operator<(Sayi& sag){ 14 | return this->deger < sag.deger; 15 | } 16 | friend ostream& operator<<(ostream& ekran,Sayi& sag){ 17 | ekran << sag.deger; 18 | return ekran; 19 | } 20 | }; 21 | 22 | int MinGetir(int& x,int& y){ 23 | return x < y ? x : y; 24 | } 25 | 26 | string MinGetir(string& x,string& y){ 27 | return x < y ? x : y; 28 | } 29 | 30 | Sayi& MinGetir(Sayi &s1,Sayi &s2){ 31 | return s1 < s2 ? s1 : s2; 32 | } 33 | 34 | int main(){ 35 | int a=10,b=21; 36 | cout<<"Min Tamsayi:"< 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object item; 11 | Node *next; 12 | 13 | Node(const Object& item,Node *next=NULL){ 14 | this->item = item; 15 | this->next = next; 16 | } 17 | }; 18 | 19 | template 20 | class Stack{ 21 | private: 22 | Node *topOfStack; 23 | 24 | public: 25 | Stack(){ 26 | topOfStack=NULL; 27 | } 28 | bool isEmpty()const{ 29 | return topOfStack == NULL; 30 | } 31 | void push(const Object& item){ 32 | topOfStack = new Node(item,topOfStack); 33 | } 34 | void pop(){ 35 | if(isEmpty()) throw "Stack is Empty"; 36 | Node *tmp = topOfStack; 37 | topOfStack = topOfStack->next; 38 | delete tmp; 39 | } 40 | const Object& top()const{ 41 | if(isEmpty()) throw "Stack is Empty"; 42 | return topOfStack->item; 43 | } 44 | void makeEmpty(){ 45 | while(!isEmpty()) pop(); 46 | } 47 | ~Stack(){ 48 | makeEmpty(); 49 | } 50 | 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Week7/Labirent/include/Stack.hpp: -------------------------------------------------------------------------------- 1 | #ifndef STACK_HPP 2 | #define STACK_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object item; 11 | Node *next; 12 | 13 | Node(const Object& item,Node *next=NULL){ 14 | this->item = item; 15 | this->next = next; 16 | } 17 | }; 18 | 19 | template 20 | class Stack{ 21 | private: 22 | Node *topOfStack; 23 | 24 | public: 25 | Stack(){ 26 | topOfStack=NULL; 27 | } 28 | bool isEmpty()const{ 29 | return topOfStack == NULL; 30 | } 31 | void push(const Object& item){ 32 | topOfStack = new Node(item,topOfStack); 33 | } 34 | void pop(){ 35 | if(isEmpty()) throw "Stack is Empty"; 36 | Node *tmp = topOfStack; 37 | topOfStack = topOfStack->next; 38 | delete tmp; 39 | } 40 | const Object& top()const{ 41 | if(isEmpty()) throw "Stack is Empty"; 42 | return topOfStack->item; 43 | } 44 | void makeEmpty(){ 45 | while(!isEmpty()) pop(); 46 | } 47 | ~Stack(){ 48 | makeEmpty(); 49 | } 50 | 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Week7/BaseConverter/include/Stack.hpp: -------------------------------------------------------------------------------- 1 | #ifndef STACK_HPP 2 | #define STACK_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object item; 11 | Node *next; 12 | 13 | Node(const Object& item,Node *next=NULL){ 14 | this->item = item; 15 | this->next = next; 16 | } 17 | }; 18 | 19 | template 20 | class Stack{ 21 | private: 22 | Node *topOfStack; 23 | 24 | public: 25 | Stack(){ 26 | topOfStack=NULL; 27 | } 28 | bool isEmpty()const{ 29 | return topOfStack == NULL; 30 | } 31 | void push(const Object& item){ 32 | topOfStack = new Node(item,topOfStack); 33 | } 34 | void pop(){ 35 | if(isEmpty()) throw "Stack is Empty"; 36 | Node *tmp = topOfStack; 37 | topOfStack = topOfStack->next; 38 | delete tmp; 39 | } 40 | const Object& top()const{ 41 | if(isEmpty()) throw "Stack is Empty"; 42 | return topOfStack->item; 43 | } 44 | void makeEmpty(){ 45 | while(!isEmpty()) pop(); 46 | } 47 | ~Stack(){ 48 | makeEmpty(); 49 | } 50 | 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Week7/CheckParentheses/include/Stack.hpp: -------------------------------------------------------------------------------- 1 | #ifndef STACK_HPP 2 | #define STACK_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object item; 11 | Node *next; 12 | 13 | Node(const Object& item,Node *next=NULL){ 14 | this->item = item; 15 | this->next = next; 16 | } 17 | }; 18 | 19 | template 20 | class Stack{ 21 | private: 22 | Node *topOfStack; 23 | 24 | public: 25 | Stack(){ 26 | topOfStack=NULL; 27 | } 28 | bool isEmpty()const{ 29 | return topOfStack == NULL; 30 | } 31 | void push(const Object& item){ 32 | topOfStack = new Node(item,topOfStack); 33 | } 34 | void pop(){ 35 | if(isEmpty()) throw "Stack is Empty"; 36 | Node *tmp = topOfStack; 37 | topOfStack = topOfStack->next; 38 | delete tmp; 39 | } 40 | const Object& top()const{ 41 | if(isEmpty()) throw "Stack is Empty"; 42 | return topOfStack->item; 43 | } 44 | void makeEmpty(){ 45 | while(!isEmpty()) pop(); 46 | } 47 | ~Stack(){ 48 | makeEmpty(); 49 | } 50 | 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Week7/Labirent/src/Konum.cpp: -------------------------------------------------------------------------------- 1 | #include "Konum.hpp" 2 | 3 | Konum::Konum(int x,int y, Yon yon){ 4 | this->x = x; 5 | this->y = y; 6 | this->yon = yon; 7 | } 8 | Konum::Konum(int x,int y){ 9 | this->x = x; 10 | this->y = y; 11 | this->yon = ASAGI; 12 | } 13 | Konum::Konum(){ 14 | x=0; 15 | y=0; 16 | yon=ASAGI; 17 | } 18 | Konum Konum::AyniYon(){ 19 | switch(yon){ 20 | case YUKARI: 21 | return Yukari(); 22 | case SAG: 23 | return Sag(); 24 | case ASAGI: 25 | return Asagi(); 26 | default: 27 | return Sol(); 28 | } 29 | } 30 | Konum Konum::SaatYonu(Yon yn){ 31 | switch(yn){ 32 | case YUKARI: 33 | return Sag(); 34 | case SAG: 35 | return Asagi(); 36 | case ASAGI: 37 | return Sol(); 38 | default: 39 | return Yukari(); 40 | } 41 | } 42 | Konum Konum::Asagi(){ 43 | return Konum(x+1,y,ASAGI); 44 | } 45 | Konum Konum::Yukari(){ 46 | return Konum(x-1,y,YUKARI); 47 | } 48 | Konum Konum::Sol(){ 49 | return Konum(x,y-1,SOL); 50 | } 51 | Konum Konum::Sag(){ 52 | return Konum(x,y+1,SAG); 53 | } 54 | Yon Konum::TersYon(){ 55 | if(yon == ASAGI) return YUKARI; 56 | if(yon == YUKARI) return ASAGI; 57 | if(yon == SOL) return SAG; 58 | if(yon == SAG) return SOL; 59 | return YUKARI; 60 | } 61 | -------------------------------------------------------------------------------- /Week7/Labirent/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Labirent.hpp" 2 | 3 | int main(){ 4 | Labirent *labirent = new Labirent(Konum(0,20),Konum(19,11)); 5 | 6 | labirent->yigit->push(Konum(labirent->x,labirent->y,ASAGI)); 7 | labirent->ayarla(Konum(labirent->x,labirent->y,ASAGI).Asagi(),ASAGI); 8 | while(!labirent->CikisaGeldimi()){ 9 | int denemeYonSayisi=1; 10 | Konum oncekiKonum = labirent->yigit->top(); 11 | Konum mevcutKonum = labirent->mevcutKonum(); 12 | 13 | Konum ileri = mevcutKonum.AyniYon(); 14 | 15 | if(!labirent->adimAt(mevcutKonum,ileri)){ 16 | int i=0; 17 | bool sonuc = false; 18 | Konum yeni = mevcutKonum; 19 | while(!sonuc && denemeYonSayisi<5){ 20 | yeni = mevcutKonum.SaatYonu((Yon)((mevcutKonum.yon+i)%4)); 21 | 22 | i++; 23 | denemeYonSayisi++; 24 | if(yeni.yon == mevcutKonum.TersYon()){ 25 | sonuc=false; 26 | } 27 | else{ 28 | sonuc = labirent->adimAt(mevcutKonum,yeni); 29 | } 30 | } 31 | if(denemeYonSayisi == 5){ 32 | labirent->yigit->pop(); 33 | labirent->ayarla(oncekiKonum,oncekiKonum.TersYon()); 34 | } 35 | } 36 | 37 | } 38 | 39 | cout<<"CIKISA GELDI"<numbers = new int[length]; 5 | this->length = length; 6 | for(int i=0;inumbers[i] = numbers[i]; } 7 | queues = new Queue*[10]; 8 | for(int j=0;j<10;j++){ queues[j] = new Queue(); } 9 | } 10 | int Radix::findMax() { 11 | int max = numbers[0]; 12 | for (int i = 1; i < length; ++i) { 13 | if (numbers[i] > max) 14 | max = numbers[i]; 15 | } 16 | return max; 17 | } 18 | int* Radix::Sort(){ 19 | int max = findMax(); 20 | int exp = 1; // basamak yeri 21 | 22 | while (max / exp > 0) { 23 | // Basamak değerine göre ilgili kuyruğa ata 24 | for (int i=0;ienqueue(numbers[i]); 27 | } 28 | 29 | // Kuyruktan sayıları alıp diziyi güncelleştir. 30 | int index = 0; 31 | for (int i = 0; i < 10; ++i) { 32 | while (!queues[i]->isEmpty()) { 33 | numbers[index++] = queues[i]->peek(); 34 | queues[i]->dequeue(); 35 | } 36 | } 37 | 38 | // Diğer basamak değerine ilerle 39 | exp *= 10; 40 | } 41 | return numbers; 42 | } 43 | Radix::~Radix(){ 44 | delete [] numbers; 45 | for(int i=0;i<10;i++) delete queues[i]; 46 | delete [] queues; 47 | } 48 | -------------------------------------------------------------------------------- /Week8/RadixSort/include/Queue.hpp: -------------------------------------------------------------------------------- 1 | #ifndef QUEUE_HPP 2 | #define QUEUE_HPP 3 | #include 4 | using namespace std; 5 | template 6 | class Queue{ 7 | private: 8 | int front; 9 | int back; 10 | int capacity; 11 | int length; 12 | Object *items; 13 | 14 | void reserve(int newCapacity){ 15 | Object *temp = new Object[newCapacity]; 16 | for(int i=front,j=0;j 2 | #include 3 | using namespace std; 4 | 5 | int** MatrisOlustur(int satir,int sutun){ 6 | int **matris = new int*[satir]; 7 | for(int i=0;icapacity = capacity; 8 | Table = new Node*[capacity]; 9 | for(int i=0;idata == number){ 21 | Node *del = Table[index]; 22 | Table[index] = del->next; 23 | delete del; 24 | return true; 25 | } 26 | Node* pre = Table[index]; 27 | while(pre->next != NULL){ 28 | if(pre->next->data == number){ 29 | Node *del = pre->next; 30 | pre->next = del->next; 31 | delete del; 32 | return true; 33 | } 34 | pre = pre->next; 35 | } 36 | return false; 37 | } 38 | void Hash::Clear(){ 39 | for(int i=0;idata); 42 | } 43 | } 44 | } 45 | bool Hash::Search(int number){ 46 | int index = HashCode(number); 47 | Node *tmp = Table[index]; 48 | while(tmp != NULL){ 49 | if(tmp->data == number) return true; 50 | tmp = tmp->next; 51 | } 52 | return false; 53 | } 54 | bool Hash::isEmpty(){ 55 | for(int i=0;i"; 65 | while(tmp != NULL){ 66 | cout<data<<"->"; 67 | tmp = tmp->next; 68 | } 69 | cout<<"->NULL"<bitis = bitis; 10 | yon = ASAGI; 11 | yigit = new Stack(); 12 | yigit->push(Konum(-1,-1,yon)); 13 | while (!feof(fp)) { 14 | karakter = getc(fp); 15 | if(karakter == 255) break; 16 | if(karakter == 10){ 17 | satir++; 18 | sutun=0; 19 | } 20 | else{ 21 | harita[satir][sutun] = karakter; 22 | sutun++; 23 | } 24 | } 25 | } 26 | Konum Labirent::mevcutKonum(){ 27 | return Konum(x,y,yon); 28 | } 29 | bool Labirent::adimAt(Konum mevcut, Konum ileri){ 30 | if(!EngelVarmi(ileri)){ 31 | yigit->push(mevcut); 32 | ayarla(ileri,ileri.yon); 33 | return true; 34 | } 35 | return false; 36 | } 37 | void Labirent::ayarla(Konum konum,Yon yon){ 38 | system("cls"); 39 | this->x = konum.x; 40 | this->y = konum.y; 41 | this->yon = yon; 42 | harita[konum.x][konum.y] = '-'; 43 | cout<= YUKSEKLIK || konum.x < 0 || konum.y >= GENISLIK || konum.y < 0) return false; 51 | return harita[konum.x][konum.y] == '#' || harita[konum.x][konum.y] == '-'; 52 | } 53 | 54 | string Labirent::yaz(){ 55 | char YonChr[] = {31,17,30,16}; 56 | stringstream ss; 57 | for(int satir=0;satiritems = new int[length]; 5 | this->capacity = length; 6 | this->length = 0; 7 | for(int index=0;index items[index]){ 31 | Swap(items[parentIndex],items[index]); 32 | HeapfyUp(parentIndex); 33 | } 34 | } 35 | } 36 | void HeapTree::HeapfyDown(int index){ 37 | int leftChildIndex,rightChildIndex,minIndex; 38 | leftChildIndex = LeftChildIndex(index); 39 | rightChildIndex = RightChildIndex(index); 40 | 41 | if(rightChildIndex >= length){ 42 | if(leftChildIndex >= length) return; 43 | else minIndex = leftChildIndex; 44 | } 45 | else{ 46 | if(items[leftChildIndex] <= items[rightChildIndex]) 47 | minIndex = leftChildIndex; 48 | else 49 | minIndex = rightChildIndex; 50 | } 51 | if(items[index] > items[minIndex]){ 52 | Swap(items[minIndex],items[index]); 53 | HeapfyDown(minIndex); 54 | } 55 | } 56 | void HeapTree::Swap(int& x,int& y){ 57 | int tmp = x; 58 | x=y; 59 | y=tmp; 60 | } 61 | 62 | bool HeapTree::IsEmpty(){ 63 | return length == 0; 64 | } 65 | 66 | int HeapTree::RemoveMin(){ 67 | if(IsEmpty()) throw "No element found"; 68 | int minItem = items[0]; 69 | items[0] = items[length - 1]; 70 | length--; 71 | if(length > 0) HeapfyDown(0); 72 | return minItem; 73 | } 74 | int* HeapTree::Sort(){ 75 | int* ordered = new int[capacity]; 76 | for(int index=0;!IsEmpty();index++){ 77 | ordered[index] = RemoveMin(); 78 | } 79 | return ordered; 80 | } 81 | HeapTree::~HeapTree(){ 82 | delete [] items; 83 | } 84 | -------------------------------------------------------------------------------- /Week8/Queue/include/Queue.hpp: -------------------------------------------------------------------------------- 1 | #ifndef QUEUE_HPP 2 | #define QUEUE_HPP 3 | 4 | #include 5 | using namespace std; 6 | 7 | template 8 | class Node{ 9 | public: 10 | Object item; 11 | Node *next; 12 | 13 | Node(Object item,Node *next=NULL){ 14 | this->item = item; 15 | this->next = next; 16 | } 17 | }; 18 | 19 | template 20 | class Queue{ 21 | private: 22 | Node *front; 23 | Node *back; 24 | int length; 25 | 26 | Node* previousMaxNode(){ 27 | Node *prev = NULL; 28 | Node *tmp = front; 29 | Object max=front->item; 30 | while(tmp->next != NULL){ 31 | if(tmp->next->item > max){ 32 | max = tmp->next->item; 33 | prev=tmp; 34 | } 35 | tmp = tmp->next; 36 | } 37 | return prev; 38 | } 39 | public: 40 | Queue(){ 41 | front=back=NULL; 42 | length=0; 43 | } 44 | int count()const{ 45 | return length; 46 | } 47 | bool isEmpty()const{ 48 | return length == 0; 49 | } 50 | void enqueue(const Object& item){ 51 | Node *last = new Node(item); 52 | if(isEmpty()) front = back = last; 53 | else{ 54 | back->next = last; 55 | back = back->next; 56 | } 57 | length++; 58 | } 59 | void dequeue(){ 60 | if(isEmpty()) throw "Queue is Empty"; 61 | Node *tmp = front; 62 | front=front->next; 63 | delete tmp; 64 | length--; 65 | } 66 | void dequeueMax(){ 67 | if(isEmpty()) throw "Queue is Empty"; 68 | Node *prev = previousMaxNode(); 69 | Node *tmp; 70 | if(prev == NULL) dequeue(); 71 | else{ 72 | if(prev->next == back) back=prev; 73 | tmp=prev->next; 74 | prev->next = prev->next->next; 75 | delete tmp; 76 | length--; 77 | } 78 | } 79 | void clear(){ 80 | while(!isEmpty())dequeue(); 81 | } 82 | Object& peek()const{ 83 | if(isEmpty()) throw "Queue is Empty"; 84 | return front->item; 85 | } 86 | Object& peekMax(){ 87 | if(isEmpty()) throw "Queue is Empty"; 88 | Node *prev = previousMaxNode(); 89 | if(prev == NULL) return peek(); 90 | return prev->next->item; 91 | } 92 | ~Queue(){ 93 | clear(); 94 | } 95 | }; 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /Week14/DoubleHashing/src/DoubleHashing.cpp: -------------------------------------------------------------------------------- 1 | #include "DoubleHashing.hpp" 2 | 3 | int DoubleHashing::Hash1(int number){ 4 | return number % capacity; 5 | } 6 | int DoubleHashing::Hash2(int number){ 7 | return R - (number % R); 8 | } 9 | bool DoubleHashing::isFull(){ 10 | return size == capacity; 11 | } 12 | bool DoubleHashing::isPrime(int number) 13 | { 14 | if (number <= 1) return false; 15 | 16 | for (int i = 2; i < number; i++) 17 | if (number % i == 0) return false; 18 | return true; 19 | } 20 | DoubleHashing::DoubleHashing(int capacity){ 21 | Table = new int[capacity]; 22 | size=0; 23 | this->capacity = capacity; 24 | R = capacity-1; 25 | while(!isPrime(R)) R--; 26 | Clear(); 27 | } 28 | void DoubleHashing::Add(int number){ 29 | if(Search(number)) return; 30 | if(isFull()) throw "Error"; 31 | int index = Hash1(number); 32 | if(Table[index] != -1){ 33 | int step = Hash2(number); 34 | int i=1; 35 | while(true){ 36 | int nIndex = (index+i*step) % capacity; 37 | if(Table[nIndex] == -1){ 38 | Table[nIndex] = number; 39 | break; 40 | } 41 | i++; 42 | } 43 | } 44 | else{ 45 | Table[index] = number; 46 | } 47 | size++; 48 | } 49 | bool DoubleHashing::Search(int number){ 50 | if(size == 0) return false; 51 | int index = Hash1(number); 52 | if(Table[index] == number) return true; 53 | int step = Hash2(number); 54 | int i=1; 55 | while(i<=size){ 56 | int nIndex = (index+i*step) % capacity; 57 | if(Table[nIndex] == number) return true; 58 | i++; 59 | } 60 | return false; 61 | } 62 | bool DoubleHashing::Remove(int number){ 63 | if(size == 0) return false; 64 | int index = Hash1(number); 65 | if(Table[index] == number){ 66 | Table[index] = -1; 67 | size--; 68 | return true; 69 | } 70 | int step = Hash2(number); 71 | int i=1; 72 | while(i<=size){ 73 | int nIndex = (index+i*step) % capacity; 74 | if(Table[nIndex] == number){ 75 | Table[index] = -1; 76 | size--; 77 | return true; 78 | } 79 | i++; 80 | } 81 | return false; 82 | } 83 | void DoubleHashing::Clear(){ 84 | for(int i=0;i 2 | #include "LinkedList.hpp" 3 | 4 | int main() 5 | { 6 | LinkedList *names = new LinkedList(); 7 | int choice=0; 8 | string name; 9 | int position; 10 | do{ 11 | system("CLS"); 12 | cout<<"[1]\tAdd Name"<>choice; 25 | system("CLS"); 26 | switch(choice){ 27 | case 1: 28 | cout<<"Name:"; 29 | cin.ignore(); 30 | getline(cin,name); 31 | names->add(name); 32 | break; 33 | case 2: 34 | cout<<"Name:"; 35 | cin.ignore(); 36 | getline(cin,name); 37 | names->remove(name); 38 | break; 39 | case 3: 40 | cout<<"Position:"; 41 | cin>>position; 42 | names->removeAt(position); 43 | break; 44 | case 4: 45 | cout<<"Position:"; 46 | cin>>position; 47 | cout<<"Name:"; 48 | cin.ignore(); 49 | getline(cin,name); 50 | names->insert(position,name); 51 | break; 52 | case 5: 53 | cout<<"Name:"; 54 | cin.ignore(); 55 | getline(cin,name); 56 | cout<<"Konum:"<indexOf(name); 57 | cin.get(); 58 | break; 59 | case 6: 60 | cout<<"Number of Names"<Count()<first()<last()<clear(); 83 | cout< *isimler = new LinkedList(); 5 | int sec,konum; 6 | string isim; 7 | 8 | do{ 9 | system("CLS"); 10 | cout<<"1.isim Ekle"<>sec; 24 | switch(sec){ 25 | case 1: 26 | cout<<"isim:"; 27 | cin.ignore(); 28 | getline(cin,isim); 29 | isimler->add(isim); 30 | break; 31 | case 2: 32 | cout<<"isim:"; 33 | cin.ignore(); 34 | getline(cin,isim); 35 | isimler->remove(isim); 36 | break; 37 | case 3: 38 | cout<<"Konum:"; 39 | cin>>konum; 40 | isimler->removeAt(konum); 41 | break; 42 | case 4: 43 | cout<<"Konum:"; 44 | cin>>konum; 45 | cout<<"isim:"; 46 | cin.ignore(); 47 | getline(cin,isim); 48 | isimler->insert(konum,isim); 49 | break; 50 | case 5: 51 | cout<<"isim:"; 52 | cin.ignore(); 53 | getline(cin,isim); 54 | cout<<"Konum:"<indexOf(isim)<size()<first()<last()<clear(); 81 | break; 82 | case 11: 83 | cout<<"isim:"; 84 | cin.ignore(); 85 | getline(cin,isim); 86 | if(isimler->find(isim)) cout<<"isim var"< 8 | class LinkedList{ 9 | private: 10 | Node *head; 11 | 12 | Node* FindPrevByPosition(int position){ 13 | if(position < 0 || position > size()) throw "Index out of range"; 14 | int index=0; 15 | Node *itr=head; 16 | for(;itr!=NULL;itr=itr->next,index++){ 17 | if(position == index) return itr; 18 | } 19 | return NULL; 20 | } 21 | public: 22 | LinkedList(){ 23 | head = new Node(Object()); 24 | } 25 | Iterator iterator(){ 26 | Iterator itr(head); 27 | return itr; 28 | } 29 | bool isEmpty() const{ 30 | return head->next == NULL; 31 | } 32 | int size() const{ 33 | int length=0; 34 | for(Node *itr=head->next;itr!=NULL;itr=itr->next){ 35 | length++; 36 | } 37 | return length; 38 | } 39 | const Object& first(){ 40 | if(isEmpty()) throw "Empty list"; 41 | return head->next->item; 42 | } 43 | const Object& last(){ 44 | if(isEmpty()) throw "Empty list"; 45 | return FindPrevByPosition(size())->item; 46 | } 47 | void add(const Object& item){ 48 | insert(size(),item); 49 | } 50 | void insert(int index,const Object& item){ 51 | Node *prev = FindPrevByPosition(index); 52 | prev->next = new Node(item,prev->next); 53 | } 54 | void remove(const Object& item){ 55 | int position = indexOf(item); 56 | removeAt(position); 57 | } 58 | void removeAt(int index){ 59 | if(isEmpty()) throw "Empty list"; 60 | Node *del; 61 | Node *prev = FindPrevByPosition(index); 62 | del = prev->next; 63 | prev->next = prev->next->next; 64 | 65 | delete del; 66 | } 67 | bool find(const Object& item) const{ 68 | for(Node *itr=head->next;itr!=NULL;itr=itr->next){ 69 | if(itr->item == item) return true; 70 | } 71 | return false; 72 | } 73 | int indexOf(const Object& item){ 74 | int index=0; 75 | for(Node *itr=head->next;itr!=NULL;itr=itr->next,index++){ 76 | if(itr->item == item) return index; 77 | } 78 | throw "Index out of range"; 79 | } 80 | friend ostream& operator<<(ostream& screen, LinkedList &right){ 81 | if(right.isEmpty()) screen<<"Empty list"; 82 | else{ 83 | for(Node *itr=right.head->next;itr!=NULL;itr=itr->next){ 84 | screen<item<<" "; 85 | } 86 | } 87 | return screen; 88 | } 89 | void clear(){ 90 | while(!isEmpty()) 91 | removeAt(0); 92 | } 93 | ~LinkedList(){ 94 | clear(); 95 | delete head; 96 | } 97 | }; 98 | #endif 99 | -------------------------------------------------------------------------------- /Week5/LinkedListIterator/LinkedList.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LinkedList_HPP 2 | #define LinkedList_HPP 3 | 4 | #include "Node.hpp" 5 | #include "Iterator.hpp" 6 | 7 | template 8 | class LinkedList{ 9 | private: 10 | Node *head; 11 | 12 | Node* FindPrevByPosition(int position){ 13 | if(position < 0 || position > size()) throw "Index out of range"; 14 | int index=0; 15 | Node *itr=head; 16 | for(;itr!=NULL;itr=itr->next,index++){ 17 | if(position == index) return itr; 18 | } 19 | return NULL; 20 | } 21 | public: 22 | LinkedList(){ 23 | head = new Node(Object()); 24 | } 25 | Iterator iterator(){ 26 | Iterator itr(head); 27 | return itr; 28 | } 29 | bool isEmpty() const{ 30 | return head->next == NULL; 31 | } 32 | int size() const{ 33 | int length=0; 34 | for(Node *itr=head->next;itr!=NULL;itr=itr->next){ 35 | length++; 36 | } 37 | return length; 38 | } 39 | const Object& first(){ 40 | if(isEmpty()) throw "Empty list"; 41 | return head->next->item; 42 | } 43 | const Object& last(){ 44 | if(isEmpty()) throw "Empty list"; 45 | return FindPrevByPosition(size())->item; 46 | } 47 | void add(const Object& item){ 48 | insert(size(),item); 49 | } 50 | void insert(int index,const Object& item){ 51 | Node *prev = FindPrevByPosition(index); 52 | prev->next = new Node(item,prev->next); 53 | } 54 | void remove(const Object& item){ 55 | int position = indexOf(item); 56 | removeAt(position); 57 | } 58 | void removeAt(int index){ 59 | if(isEmpty()) throw "Empty list"; 60 | Node *del; 61 | Node *prev = FindPrevByPosition(index); 62 | del = prev->next; 63 | prev->next = prev->next->next; 64 | 65 | delete del; 66 | } 67 | bool find(const Object& item) const{ 68 | for(Node *itr=head->next;itr!=NULL;itr=itr->next){ 69 | if(itr->item == item) return true; 70 | } 71 | return false; 72 | } 73 | int indexOf(const Object& item){ 74 | int index=0; 75 | for(Node *itr=head->next;itr!=NULL;itr=itr->next,index++){ 76 | if(itr->item == item) return index; 77 | } 78 | throw "Index out of range"; 79 | } 80 | friend ostream& operator<<(ostream& screen, LinkedList &right){ 81 | if(right.isEmpty()) screen<<"Empty list"; 82 | else{ 83 | for(Node *itr=right.head->next;itr!=NULL;itr=itr->next){ 84 | screen<item<<" "; 85 | } 86 | } 87 | return screen; 88 | } 89 | void clear(){ 90 | while(!isEmpty()) 91 | removeAt(0); 92 | } 93 | ~LinkedList(){ 94 | clear(); 95 | delete head; 96 | } 97 | }; 98 | #endif 99 | -------------------------------------------------------------------------------- /Week5/LinkedListv2/LinkedList.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LinkedList_HPP 2 | #define LinkedList_HPP 3 | 4 | #include "Node.hpp" 5 | 6 | template 7 | class LinkedList{ 8 | private: 9 | Node *head; 10 | int size; 11 | 12 | Node* FindPrevByPosition(int position){ 13 | if(position < 0 || position > size) throw "Index out of range"; 14 | int index=1; 15 | 16 | for(Node *itr=head;itr!=NULL;itr=itr->next,index++){ 17 | if(position == index) return itr; 18 | } 19 | return NULL; 20 | } 21 | public: 22 | LinkedList(){ 23 | head = NULL; 24 | size=0; 25 | } 26 | bool isEmpty() const{ 27 | return head == NULL; 28 | } 29 | int Count() const{ 30 | return size; 31 | } 32 | const Object& first(){ 33 | if(isEmpty()) throw "Empty list"; 34 | return head->item; 35 | } 36 | const Object& last(){ 37 | if(isEmpty()) throw "Empty list"; 38 | return FindPrevByPosition(size)->item; 39 | } 40 | void add(const Object& item){ 41 | insert(size,item); 42 | } 43 | void insert(int index,const Object& item){ 44 | if(index == 0) head = new Node(item, head); 45 | else{ 46 | Node *prev = FindPrevByPosition(index); 47 | prev->next = new Node(item,prev->next); 48 | } 49 | size++; 50 | } 51 | void remove(const Object& item){ 52 | int position = indexOf(item); 53 | removeAt(position); 54 | } 55 | void removeAt(int index){ 56 | if(size == 0) throw "Empty list"; 57 | Node *del; 58 | if(index == 0){ 59 | del = head; 60 | head = head->next; 61 | } 62 | else{ 63 | Node *prev = FindPrevByPosition(index); 64 | del = prev->next; 65 | prev->next = prev->next->next; 66 | } 67 | delete del; 68 | size--; 69 | } 70 | bool find(const Object& item) const{ 71 | for(Node *itr=head;itr!=NULL;itr=itr->next){ 72 | if(itr->item == item) return true; 73 | } 74 | return false; 75 | } 76 | int indexOf(const Object& item){ 77 | int index=0; 78 | for(Node *itr=head;itr!=NULL;itr=itr->next,index++){ 79 | if(itr->item == item) return index; 80 | } 81 | throw "Index out of range"; 82 | } 83 | friend ostream& operator<<(ostream& screen, LinkedList &right){ 84 | if(right.isEmpty()) screen<<"Empty list"; 85 | else{ 86 | for(Node *itr=right.head;itr!=NULL;itr=itr->next){ 87 | screen<item<<" "; 88 | } 89 | } 90 | return screen; 91 | } 92 | void clear(){ 93 | while(!isEmpty()) 94 | removeAt(0); 95 | } 96 | ~LinkedList(){ 97 | clear(); 98 | } 99 | }; 100 | #endif 101 | -------------------------------------------------------------------------------- /Week13/Huffman/src/Huffman.cpp: -------------------------------------------------------------------------------- 1 | #include "Huffman.hpp" 2 | 3 | Node* Huffman::CreateTree(int freq[]){ 4 | Node *nodes[symbols]; 5 | for(int i=0;i0){ 7 | nodes[i] = new Node((char)i,freq[i]); 8 | } 9 | else{ 10 | nodes[i] = NULL; 11 | } 12 | } 13 | 14 | while(true){ 15 | int firstIndex = MinNodeIndex(nodes); 16 | Node* min1 = nodes[firstIndex]; 17 | nodes[firstIndex] = NULL; 18 | int secondIndex = MinNodeIndex(nodes); 19 | if(secondIndex == -1) return min1; 20 | Node *min2 = nodes[secondIndex]; 21 | nodes[secondIndex] = NULL; 22 | nodes[firstIndex] = new Node(0,min1->freq+min2->freq,min1,min2); 23 | } 24 | } 25 | void Huffman::AssignCodes(Node* subNode,string code){ 26 | if(subNode == NULL) return; 27 | if(!subNode->isLeaf()){ 28 | AssignCodes(subNode->left,code+"0"); 29 | AssignCodes(subNode->right,code+"1"); 30 | } 31 | else{ 32 | subNode->code = code; 33 | } 34 | } 35 | int Huffman::MinNodeIndex(Node* trees[]){ 36 | Node *min; 37 | int minIndex = -1; 38 | 39 | for(int i=0;i *trees[i]){ 51 | min = trees[i]; 52 | minIndex = i; 53 | } 54 | } 55 | return minIndex; 56 | } 57 | void Huffman::ReadFile(string path){ 58 | string line; 59 | ifstream file(path.c_str()); 60 | while(getline(file,line)){ 61 | input += line; 62 | input += "\n"; 63 | } 64 | file.close(); 65 | } 66 | void Huffman::inorder(Node* subNode){ 67 | if(subNode != NULL){ 68 | inorder(subNode->left); 69 | if(subNode->isLeaf()) cout<chracter<<":"<code<right); 71 | } 72 | } 73 | void Huffman::RemoveNode(Node*& subNode){ 74 | if(subNode != NULL){ 75 | RemoveNode(subNode->left); 76 | RemoveNode(subNode->right); 77 | delete subNode; 78 | subNode = NULL; 79 | } 80 | } 81 | Huffman::Huffman(string path){ 82 | symbols = 256; 83 | ReadFile(path); 84 | root = NULL; 85 | } 86 | void Huffman::Encode(){ 87 | char chars[input.size()-1]; 88 | strcpy(chars,input.c_str()); 89 | 90 | int freq[symbols]; 91 | for(int i=0;i 3 | #include "CircularLinkedList.hpp" 4 | 5 | int main() 6 | { 7 | CircularLinkedList *isimler = new CircularLinkedList(); 8 | int sec=0; 9 | string isim; 10 | int konum; 11 | 12 | do{ 13 | system("CLS"); 14 | cout<<"1.Isim Ekle"<>sec; 28 | system("CLS"); 29 | switch(sec){ 30 | case 1: 31 | cout<<"Isim:"; 32 | cin.ignore(); 33 | getline(cin,isim); 34 | isimler->add(isim); 35 | break; 36 | case 2: 37 | cout<<"Isim:"; 38 | cin.ignore(); 39 | getline(cin,isim); 40 | isimler->remove(isim); 41 | break; 42 | case 3: 43 | cout<<"Konum:"; 44 | cin>>konum; 45 | isimler->removeAt(konum); 46 | break; 47 | case 4: 48 | cout<<"Konum:"; 49 | cin>>konum; 50 | cout<<"Isim:"; 51 | cin.ignore(); 52 | getline(cin,isim); 53 | isimler->insert(konum,isim); 54 | break; 55 | case 5: 56 | cout<<"Isim:"; 57 | cin.ignore(); 58 | getline(cin,isim); 59 | cout<<"Konum:"<indexOf(isim); 60 | cin.ignore(); 61 | cin.get(); 62 | break; 63 | case 6: 64 | cout<<"Isim Sayisi:"<Count()<first()<last()<clear(); 86 | cout<>konum; 93 | isimler->printAllFromPosition(konum); 94 | cin.ignore(); 95 | cin.get(); 96 | break; 97 | case 12: 98 | break; 99 | default: 100 | cout< 3 | #include "DoublyLinkedList.hpp" 4 | 5 | int main() 6 | { 7 | DoublyLinkedList *isimler = new DoublyLinkedList(); 8 | int sec=0; 9 | string isim; 10 | int konum; 11 | 12 | do{ 13 | system("CLS"); 14 | cout<<"1.Isim Ekle"<>sec; 29 | system("CLS"); 30 | switch(sec){ 31 | case 1: 32 | cout<<"Isim:"; 33 | cin.ignore(); 34 | getline(cin,isim); 35 | isimler->add(isim); 36 | break; 37 | case 2: 38 | cout<<"Isim:"; 39 | cin.ignore(); 40 | getline(cin,isim); 41 | isimler->remove(isim); 42 | break; 43 | case 3: 44 | cout<<"Konum:"; 45 | cin>>konum; 46 | isimler->removeAt(konum); 47 | break; 48 | case 4: 49 | cout<<"Konum:"; 50 | cin>>konum; 51 | cout<<"Isim:"; 52 | cin.ignore(); 53 | getline(cin,isim); 54 | isimler->insert(konum,isim); 55 | break; 56 | case 5: 57 | cout<<"Isim:"; 58 | cin.ignore(); 59 | getline(cin,isim); 60 | cout<<"Konum:"<indexOf(isim); 61 | cin.ignore(); 62 | cin.get(); 63 | break; 64 | case 6: 65 | cout<<"Isim Sayisi:"<Count()<first()<last()<clear(); 87 | cout<>konum; 94 | isimler->printNodesFromPositionInReverseOrder(konum); 95 | cin.ignore(); 96 | cin.get(); 97 | break; 98 | case 12: 99 | isimler->printReverseOrder(); 100 | cin.ignore(); 101 | cin.get(); 102 | break; 103 | case 13: 104 | break; 105 | default: 106 | cout<* stack,string& postfix){ 12 | postfix += stack->top(); 13 | postfix += " "; 14 | stack->pop(); 15 | } 16 | string Postfix::infixToPostfix(string infix){ 17 | int length = infix.length(); 18 | Stack *stack = new Stack(); 19 | string postfix = ""; 20 | 21 | for(int i=0;ipush(infix[i]); 32 | } 33 | else if(infix[i] == '*' || infix[i] == '+' || infix[i] == '-' || infix[i] == '/'){ 34 | while(!stack->isEmpty() && stack->top() != '('){ 35 | if(IsPriorityLow(stack->top(),infix[i])){ 36 | CopyPostfix(stack,postfix); 37 | } 38 | else break; 39 | } 40 | stack->push(infix[i]); 41 | } 42 | else if(infix[i] == ')'){ 43 | while(!stack->isEmpty() && stack->top() != '('){ 44 | CopyPostfix(stack,postfix); 45 | } 46 | if(!stack->isEmpty()) stack->pop(); 47 | } 48 | } 49 | while(!stack->isEmpty()){ 50 | CopyPostfix(stack,postfix); 51 | } 52 | delete stack; 53 | return postfix; 54 | } 55 | double Postfix::StringToDouble(string str){ 56 | stringstream ss(str); 57 | double num; 58 | ss>>num; 59 | return num; 60 | } 61 | 62 | Postfix::Postfix(string infix){ 63 | value = infixToPostfix(infix); 64 | } 65 | double Postfix::Calculate(){ 66 | double result; 67 | int length = value.length(); 68 | Stack *stack = new Stack(); 69 | for(int i=0;ipush(number); 80 | i--; 81 | continue; 82 | } 83 | else{ 84 | double number2 = stack->top(); 85 | stack->pop(); 86 | double number1 = stack->top(); 87 | stack->pop(); 88 | switch(value[i]){ 89 | case '+': 90 | stack->push(number1+number2); 91 | break; 92 | case '-': 93 | stack->push(number1-number2); 94 | break; 95 | case '*': 96 | stack->push(number1*number2); 97 | break; 98 | case '/': 99 | stack->push(number1/number2); 100 | break; 101 | } 102 | } 103 | } 104 | if(!stack->isEmpty()){ 105 | result = stack->top(); 106 | stack->pop(); 107 | } 108 | delete stack; 109 | return result; 110 | } 111 | string Postfix::GetPostfixValue()const{ 112 | return value; 113 | } 114 | ostream& operator<<(ostream& screen, Postfix& rgt){ 115 | screen< 9 | class ArrayList{ 10 | private: 11 | Object *items; 12 | int length; 13 | int capacity; 14 | void reserve(int newCapacity) 15 | { 16 | if(capacity>=newCapacity) return; 17 | Object *tmp = new Object[newCapacity]; 18 | for(int j=0;jlength()]; 34 | for(int i=0;i=length) throw NoSuchElement("No Such Element"); 57 | return items[i]; 58 | } 59 | void remove(const Object& item) throw(NoSuchElement) 60 | { 61 | for(int i=0;i=length) throw NoSuchElement("No Such Element"); 72 | for(int j=i+1;jlength) throw IndexOutOfBound("Index Out Of Bound"); 82 | if(length >= capacity) reserve(max(1,2*capacity)); 83 | for(int j=length-1;j>=i;j--) items[j + 1] = items[j]; 84 | items[i] = item; 85 | length++; 86 | } 87 | const Object& first() const throw(EmptyList) 88 | { 89 | if(length == 0) throw EmptyList("List is empty"); 90 | return items[0]; 91 | } 92 | const Object& last() const throw(EmptyList){ 93 | if(length == 0) throw EmptyList("List is empty"); 94 | return items[length-1]; 95 | } 96 | void clear() 97 | { 98 | length = 0; 99 | } 100 | friend ostream& operator<<(ostream& screen,ArrayList& right){ 101 | screen< 3 | #include "CircularDoublyLinkedList.hpp" 4 | 5 | int main() 6 | { 7 | CircularDoublyLinkedList *isimler = new CircularDoublyLinkedList(); 8 | int sec=0; 9 | string isim; 10 | int konum; 11 | 12 | do{ 13 | system("CLS"); 14 | cout<<"1.Isim Ekle"<>sec; 30 | system("CLS"); 31 | switch(sec){ 32 | case 1: 33 | cout<<"Isim:"; 34 | cin.ignore(); 35 | getline(cin,isim); 36 | isimler->add(isim); 37 | break; 38 | case 2: 39 | cout<<"Isim:"; 40 | cin.ignore(); 41 | getline(cin,isim); 42 | isimler->remove(isim); 43 | break; 44 | case 3: 45 | cout<<"Konum:"; 46 | cin>>konum; 47 | isimler->removeAt(konum); 48 | break; 49 | case 4: 50 | cout<<"Konum:"; 51 | cin>>konum; 52 | cout<<"Isim:"; 53 | cin.ignore(); 54 | getline(cin,isim); 55 | isimler->insert(konum,isim); 56 | break; 57 | case 5: 58 | cout<<"Isim:"; 59 | cin.ignore(); 60 | getline(cin,isim); 61 | cout<<"Konum:"<indexOf(isim); 62 | cin.ignore(); 63 | cin.get(); 64 | break; 65 | case 6: 66 | cout<<"Isim Sayisi:"<Count()<first()<last()<clear(); 88 | cout<>konum; 95 | isimler->printNodesFromPositionInReverseOrder(konum); 96 | cin.ignore(); 97 | cin.get(); 98 | break; 99 | case 12: 100 | isimler->printReverseOrder(); 101 | cin.ignore(); 102 | cin.get(); 103 | break; 104 | case 13: 105 | cout<<"Konum:"; 106 | cin>>konum; 107 | isimler->printNodesFromPositionInOrder(konum); 108 | cin.ignore(); 109 | cin.get(); 110 | break; 111 | case 14: 112 | break; 113 | default: 114 | cout< 3 | #include "ArrayList.hpp" 4 | 5 | int main() 6 | { 7 | ArrayList *isimler = new ArrayList(); 8 | int sec=0; 9 | string isim; 10 | do{ 11 | system("CLS"); 12 | cout<<"1.Isim Ekle"<>sec; 25 | system("CLS"); 26 | switch(sec){ 27 | case 1: 28 | cout<<"Isim:"; 29 | cin.ignore(); 30 | getline(cin,isim); 31 | isimler->add(isim); 32 | break; 33 | case 2: 34 | cout<<"Isim:"; 35 | cin.ignore(); 36 | getline(cin,isim); 37 | try{ 38 | isimler->remove(isim); 39 | } 40 | catch(NoSuchElement &elemanYok){ 41 | cout<>konum; 50 | isimler->removeAt(konum); 51 | } 52 | catch(NoSuchElement &elemanYok){ 53 | cout<>konum; 64 | cout<<"Isim:"; 65 | cin.ignore(); 66 | getline(cin,isim); 67 | isimler->insert(konum,isim); 68 | } 69 | catch(IndexOutOfBound &tasma){ 70 | cout<indexOf(isim); 81 | cin.get(); 82 | } 83 | catch(NoSuchElement &elemanYok){ 84 | cout<size()<first()<last()<clear(); 125 | cout< 8 | class CircularLinkedList{ 9 | private: 10 | Node *head; 11 | int size; 12 | 13 | Iterator FindPrevByPosition(int position){ 14 | if(position < 0 || position > size) throw NoSuchElement("No Such Element"); 15 | int index=0; 16 | Iterator iterator(head); 17 | while(position != index){ 18 | iterator.next(); 19 | index++; 20 | } 21 | return iterator; 22 | } 23 | void updateLastNode(){ 24 | Node *lastNode = FindPrevByPosition(size).current; 25 | lastNode->next = head->next; 26 | } 27 | public: 28 | CircularLinkedList(){ 29 | head = new Node(); 30 | size=0; 31 | } 32 | bool isEmpty()const{ 33 | return head->next == NULL; 34 | } 35 | int Count()const{ 36 | return size; 37 | } 38 | void add(const Object& item){ 39 | insert(size,item); 40 | } 41 | void insert(int index,const Object& item){ 42 | Iterator iterator = FindPrevByPosition(index); 43 | iterator.current->next = new Node(item,iterator.current->next); 44 | size++; 45 | 46 | if(index == 0) updateLastNode(); 47 | } 48 | const Object& first()const throw(NoSuchElement){ 49 | if(isEmpty()) throw NoSuchElement("No Such Element"); 50 | return head->next->item; 51 | } 52 | const Object& last()throw(NoSuchElement){ 53 | if(isEmpty()) throw NoSuchElement("No Such Element"); 54 | return FindPrevByPosition(size).getCurrent(); 55 | } 56 | int indexOf(const Object& item)throw(NoSuchElement){ 57 | int index=0; 58 | for(Iterator iterator(head->next);index= size) throw NoSuchElement("No Such Element"); 66 | Iterator iterator = FindPrevByPosition(index); 67 | return iterator.current->next->item; 68 | } 69 | bool find(const Object& item)const{ 70 | for(Iterator iterator(head->next);iterator.hasNext();iterator.next()){ 71 | if(iterator.getCurrent() == item) return true; 72 | } 73 | return false; 74 | } 75 | void remove(const Object& item){ 76 | int index = indexOf(item); 77 | removeAt(index); 78 | } 79 | void removeAt(int index)throw(NoSuchElement){ 80 | if(index < 0 || index >= size) throw NoSuchElement("No Such Element"); 81 | Iterator iterator = FindPrevByPosition(index); 82 | Node *del = iterator.current->next; 83 | iterator.current->next = iterator.current->next->next; 84 | delete del; 85 | size--; 86 | 87 | if(size != 0 && index == 0) updateLastNode(); 88 | } 89 | friend ostream& operator<<(ostream& screen,CircularLinkedList &right) 90 | { 91 | int index=0; 92 | for(Iterator iterator(right.head->next);index "; 94 | index++; 95 | } 96 | screen<<"NULL"<= size) throw NoSuchElement("No Such Element"); 101 | Iterator iterator = FindPrevByPosition(index); 102 | int ind=0; 103 | for(iterator.next();ind "; 105 | } 106 | cout< 5 | #include 6 | using namespace std; 7 | 8 | template 9 | struct Node{ 10 | Object data; 11 | Node *left; 12 | Node *right; 13 | 14 | Node(const Object& dt,Node *lf=NULL,Node *rg=NULL){ 15 | data = dt; 16 | left = lf; 17 | right = rg; 18 | } 19 | }; 20 | 21 | template 22 | class BST{ 23 | private: 24 | Node *root; 25 | 26 | void SearchAndAdd(Node *&subNode,const Object& newItem){ 27 | if(subNode == NULL) subNode = new Node(newItem); 28 | else if(newItem < subNode->data) 29 | SearchAndAdd(subNode->left,newItem); 30 | else if(newItem > subNode->data) 31 | SearchAndAdd(subNode->right,newItem); 32 | else return; 33 | } 34 | bool SearchAndDelete(Node *&subNode,const Object& data){ 35 | if(subNode == NULL) return false; 36 | if(subNode->data == data) return DeleteNode(subNode); 37 | else if(data < subNode->data) return SearchAndDelete(subNode->left,data); 38 | else return SearchAndDelete(subNode->right,data); 39 | } 40 | bool DeleteNode(Node *&subNode){ 41 | Node *DelNode = subNode; 42 | 43 | if(subNode->right == NULL) subNode = subNode->left; 44 | else if(subNode->left == NULL) subNode = subNode->right; 45 | else{ 46 | DelNode = subNode->left; 47 | Node *parent = subNode; 48 | while(DelNode->right != NULL){ 49 | parent = DelNode; 50 | DelNode = DelNode->right; 51 | } 52 | subNode->data = DelNode->data; 53 | if(parent == subNode) subNode->left = DelNode->left; 54 | else parent->right = DelNode->left; 55 | } 56 | delete DelNode; 57 | return true; 58 | } 59 | void inorder(Node *subNode){ 60 | if(subNode != NULL){ 61 | inorder(subNode->left); 62 | cout<data<<" "; 63 | inorder(subNode->right); 64 | } 65 | } 66 | void preorder(Node *subNode){ 67 | if(subNode != NULL){ 68 | cout<data<<" "; 69 | preorder(subNode->left); 70 | preorder(subNode->right); 71 | } 72 | } 73 | void postorder(Node *subNode){ 74 | if(subNode != NULL){ 75 | postorder(subNode->left); 76 | postorder(subNode->right); 77 | cout<data<<" "; 78 | } 79 | } 80 | 81 | int Height(Node *subNode){ 82 | if(subNode == NULL) return -1; 83 | return 1+max(Height(subNode->left),Height(subNode->right)); 84 | } 85 | void PrintLevel(Node *subNode,int level){ 86 | if(subNode == NULL) return; 87 | if(level == 0) cout<data<<" "; 88 | else{ 89 | PrintLevel(subNode->left,level-1); 90 | PrintLevel(subNode->right,level-1); 91 | } 92 | } 93 | bool Search(Node *subNode,const Object& item){ 94 | if(subNode == NULL) return false; 95 | if(subNode->data == item) return true; 96 | if(item < subNode->data) return Search(subNode->left,item); 97 | else return Search(subNode->right,item); 98 | } 99 | public: 100 | BST(){ 101 | root = NULL; 102 | } 103 | bool isEmpty()const{ 104 | return root == NULL; 105 | } 106 | void Add(const Object& newItem){ 107 | SearchAndAdd(root,newItem); 108 | } 109 | void Delete(const Object &data){ 110 | if(SearchAndDelete(root,data) == false) throw "Item not found."; 111 | } 112 | void inorder(){ 113 | inorder(root); 114 | } 115 | void preorder(){ 116 | preorder(root); 117 | } 118 | void postorder(){ 119 | postorder(root); 120 | } 121 | void levelorder(){ 122 | int h = Height(); 123 | for(int level=0;level<=h;level++){ 124 | PrintLevel(root,level); 125 | } 126 | } 127 | int Height(){ 128 | return Height(root); 129 | } 130 | bool Search(const Object& item){ 131 | return Search(root,item); 132 | } 133 | void Clear(){ 134 | while(!isEmpty()) DeleteNode(root); 135 | } 136 | ~BST(){ 137 | Clear(); 138 | } 139 | }; 140 | 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /Week6/DoublyLinkedList/include/DoublyLinkedList.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DOUBLYLINKEDLIST 2 | #define DOUBLYLINKEDLIST 3 | 4 | #include "Node.hpp" 5 | #include "NoSuchElement.hpp" 6 | 7 | template 8 | class DoublyLinkedList{ 9 | private: 10 | Node *head; 11 | int size; 12 | 13 | Node* FindPreviousByPosition(int index)throw(NoSuchElement){ 14 | if(index < 0 || index > size) throw NoSuchElement("No Such Element"); 15 | Node *prv = head; 16 | int i=1; 17 | for(Node *itr = head; itr->next != NULL && i != index; itr=itr->next,i++){ 18 | prv = prv->next; 19 | } 20 | return prv; 21 | } 22 | public: 23 | DoublyLinkedList(){ 24 | head = NULL; 25 | size=0; 26 | } 27 | int Count()const{ 28 | return size; 29 | } 30 | bool isEmpty()const{ 31 | return size == 0; 32 | } 33 | void add(const Object& item){ 34 | insert(size,item); 35 | } 36 | void insert(int index,const Object& item){ 37 | if(index < 0 || index > size) throw "Index out of Range"; 38 | if(index == 0){ 39 | head = new Node(item,head); 40 | if(head->next != NULL) head->next->prev = head; 41 | } 42 | else{ 43 | Node *prv = FindPreviousByPosition(index); 44 | prv->next = new Node(item,prv->next,prv); 45 | if(prv->next->next != NULL) 46 | prv->next->next->prev = prv->next; 47 | } 48 | size++; 49 | } 50 | const Object& first()throw(NoSuchElement){ 51 | if(isEmpty()) throw NoSuchElement("No Such Element"); 52 | return head->data; 53 | } 54 | const Object& last()throw(NoSuchElement){ 55 | if(isEmpty()) throw NoSuchElement("No Such Element"); 56 | return FindPreviousByPosition(size)->data; 57 | } 58 | int indexOf(const Object& item)throw(NoSuchElement){ 59 | int index=0; 60 | for(Node *itr=head;itr!=NULL;itr=itr->next){ 61 | if(itr->data == item) return index; 62 | index++; 63 | } 64 | throw NoSuchElement("No Such Element"); 65 | } 66 | void remove(const Object& item){ 67 | int index = indexOf(item); 68 | removeAt(index); 69 | } 70 | void removeAt(int index){ 71 | if(index < 0 || index >= size) throw "Index out of Range"; 72 | Node *del; 73 | if(index == 0){ 74 | del = head; 75 | head = head->next; 76 | if(head != NULL) head->prev = NULL; 77 | } 78 | else{ 79 | Node *prv = FindPreviousByPosition(index); 80 | del = prv->next; 81 | prv->next = del->next; 82 | if(del->next != NULL) 83 | del->next->prev = prv; 84 | } 85 | size--; 86 | delete del; 87 | } 88 | bool find(const Object& item){ 89 | for(Node *itr=head;itr!=NULL;itr=itr->next){ 90 | if(itr->data == item) return true; 91 | } 92 | return false; 93 | } 94 | void reverse(){ 95 | for(Node *itr=head;itr!=NULL;){ 96 | Node *tmp = itr->next; 97 | itr->next = itr->prev; 98 | itr->prev = tmp; 99 | if(tmp == NULL){ 100 | head = itr; 101 | break; 102 | } 103 | itr=tmp; 104 | } 105 | } 106 | const Object& elementAt(int index)throw(NoSuchElement){ 107 | if(index < 0 || index >= size) throw NoSuchElement("No Such Element"); 108 | if(index == 0) return head->data; 109 | return FindPreviousByPosition(index)->next->data; 110 | } 111 | void clear(){ 112 | while(!isEmpty()) 113 | removeAt(0); 114 | } 115 | friend ostream& operator<<(ostream& screen,DoublyLinkedList& rgt){ 116 | for(Node *itr=rgt.head;itr!=NULL;itr=itr->next){ 117 | screen<data<<" <-> "; 118 | } 119 | screen<= size) throw NoSuchElement("No Such Element"); 124 | for(Node *itr = FindPreviousByPosition(index+1);itr!=NULL;itr=itr->prev){ 125 | cout<data<<" <-> "; 126 | } 127 | cout< 8 | class CircularDoublyLinkedList{ 9 | private: 10 | Node *head; 11 | int size; 12 | 13 | Node* FindPreviousByPosition(int index){ 14 | Node *prv = head; 15 | int i=1; 16 | for(Node *itr = head; i != index; itr=itr->next,i++){ 17 | prv = prv->next; 18 | } 19 | return prv; 20 | } 21 | public: 22 | CircularDoublyLinkedList(){ 23 | head = NULL; 24 | size=0; 25 | } 26 | int Count()const{ 27 | return size; 28 | } 29 | bool isEmpty()const{ 30 | return size == 0; 31 | } 32 | void add(const Object& item){ 33 | insert(size,item); 34 | } 35 | void insert(int index,const Object& item)throw(NoSuchElement){ 36 | if(index < 0 || index > size) throw NoSuchElement("No Such Element"); 37 | if(index == 0){ 38 | if(size == 0){ 39 | head = new Node(item,head); 40 | head->next=head->prev=head; 41 | } 42 | else{ 43 | head = new Node(item,head,head->prev); 44 | head->next->prev = head; 45 | head->prev->next = head; 46 | } 47 | } 48 | else{ 49 | Node *prv = FindPreviousByPosition(index); 50 | prv->next = new Node(item,prv->next,prv); 51 | prv->next->next->prev = prv->next; 52 | } 53 | size++; 54 | } 55 | const Object& first()throw(NoSuchElement){ 56 | if(isEmpty()) throw NoSuchElement("No Such Element"); 57 | return head->data; 58 | } 59 | const Object& last()throw(NoSuchElement){ 60 | if(isEmpty()) throw NoSuchElement("No Such Element"); 61 | return head->prev->data; 62 | } 63 | int indexOf(const Object& item)throw(NoSuchElement){ 64 | int index=0; 65 | for(Node *itr=head;indexnext){ 66 | if(itr->data == item) return index; 67 | index++; 68 | } 69 | throw NoSuchElement("No Such Element"); 70 | } 71 | void remove(const Object& item){ 72 | int index = indexOf(item); 73 | removeAt(index); 74 | } 75 | void removeAt(int index)throw(NoSuchElement){ 76 | if(index < 0 || index >= size) throw NoSuchElement("No Such Element"); 77 | Node *del; 78 | if(index == 0){ 79 | del = head; 80 | if(size == 1) head = NULL; 81 | else{ 82 | head = head->next; 83 | head->prev = del->prev; 84 | del->prev->next = head; 85 | } 86 | } 87 | else{ 88 | Node *prv = FindPreviousByPosition(index); 89 | del = prv->next; 90 | prv->next = del->next; 91 | del->next->prev = prv; 92 | } 93 | size--; 94 | delete del; 95 | } 96 | bool find(const Object& item){ 97 | int index=0; 98 | for(Node *itr=head;indexnext,index++){ 99 | if(itr->data == item) return true; 100 | } 101 | return false; 102 | } 103 | const Object& elementAt(int index)throw(NoSuchElement){ 104 | if(index < 0 || index >= size) throw NoSuchElement("No Such Element"); 105 | if(index == 0) return head->data; 106 | return FindPreviousByPosition(index)->next->data; 107 | } 108 | void clear(){ 109 | while(!isEmpty()) 110 | removeAt(0); 111 | } 112 | friend ostream& operator<<(ostream& screen,CircularDoublyLinkedList& rgt){ 113 | int index=0; 114 | for(Node *itr=rgt.head;indexnext,index++){ 115 | screen<data<<" <-> "; 116 | } 117 | screen<= size) throw NoSuchElement("No Such Element"); 123 | for(Node *itr = FindPreviousByPosition(index+1);iprev,i++){ 124 | cout<data<<" <-> "; 125 | } 126 | cout<= size) throw NoSuchElement("No Such Element"); 131 | for(Node *itr = FindPreviousByPosition(index+1);inext,i++){ 132 | cout<data<<" <-> "; 133 | } 134 | cout< 5 | #include 6 | using namespace std; 7 | 8 | template 9 | struct Node{ 10 | Object data; 11 | Node *left; 12 | Node *right; 13 | int height; 14 | 15 | Node(const Object& vr,Node *sl=NULL,Node *sg=NULL){ 16 | data = vr; 17 | left = sl; 18 | right = sg; 19 | height=0; 20 | } 21 | }; 22 | 23 | template 24 | class AVL{ 25 | private: 26 | Node *root; 27 | 28 | Node* SearchAndAdd(Node *subNode,const Object& item){ 29 | if(subNode == NULL) subNode = new Node(item); 30 | else if(item < subNode->data){ 31 | subNode->left = SearchAndAdd(subNode->left,item); 32 | 33 | if(Height(subNode->left) == Height(subNode->right)+2){ 34 | if(item < subNode->left->data) 35 | subNode = SwapWithLeftChild(subNode); 36 | else{ 37 | subNode->left = SwapWithRightChild(subNode->left); 38 | subNode = SwapWithLeftChild(subNode); 39 | } 40 | } 41 | } 42 | else if(item > subNode->data){ 43 | subNode->right = SearchAndAdd(subNode->right,item); 44 | 45 | if(Height(subNode->right) == Height(subNode->left)+2){ 46 | if(item > subNode->right->data) 47 | subNode = SwapWithRightChild(subNode); 48 | else{ 49 | subNode->right = SwapWithLeftChild(subNode->right); 50 | subNode = SwapWithRightChild(subNode); 51 | } 52 | } 53 | } 54 | else; 55 | 56 | subNode->height = Height(subNode); 57 | return subNode; 58 | } 59 | Node* SwapWithLeftChild(Node *subNode){ 60 | Node *tmp = subNode->left; 61 | subNode->left = tmp->right; 62 | tmp->right = subNode; 63 | 64 | subNode->height = Height(subNode); 65 | tmp->height = 1+max(Height(tmp->left),subNode->height); 66 | 67 | return tmp; 68 | } 69 | Node* SwapWithRightChild(Node *subNode){ 70 | Node *tmp = subNode->right; 71 | subNode->right = tmp->left; 72 | tmp->left = subNode; 73 | 74 | subNode->height = Height(subNode); 75 | tmp->height = 1+max(Height(tmp->right),subNode->height); 76 | 77 | return tmp; 78 | } 79 | bool DeleteNode(Node *&subNode){ 80 | Node *delNode = subNode; 81 | 82 | if(subNode->right == NULL) subNode = subNode->left; 83 | else if(subNode->left == NULL) subNode = subNode->right; 84 | else{ 85 | delNode = subNode->left; 86 | Node *parentNode = subNode; 87 | while(delNode->right != NULL){ 88 | parentNode = delNode; 89 | delNode = delNode->right; 90 | } 91 | subNode->data = delNode->data; 92 | if(parentNode == subNode) subNode->left = delNode->left; 93 | else parentNode->right = delNode->left; 94 | } 95 | delete delNode; 96 | return true; 97 | } 98 | void inorder(Node *subNode){ 99 | if(subNode != NULL){ 100 | inorder(subNode->left); 101 | cout<data<<" "; 102 | inorder(subNode->right); 103 | } 104 | } 105 | void preorder(Node *subNode){ 106 | if(subNode != NULL){ 107 | cout<data<<" "; 108 | preorder(subNode->left); 109 | preorder(subNode->right); 110 | } 111 | } 112 | void postorder(Node *subNode){ 113 | if(subNode != NULL){ 114 | postorder(subNode->left); 115 | postorder(subNode->right); 116 | cout<data<<" "; 117 | } 118 | } 119 | 120 | int Height(Node *subNode){ 121 | if(subNode == NULL) return -1; 122 | return 1+max(Height(subNode->left),Height(subNode->right)); 123 | } 124 | void PrintLevel(Node *subNode,int level){ 125 | if(subNode == NULL) return; 126 | if(level == 0) cout<data<<" "; 127 | else{ 128 | PrintLevel(subNode->left,level-1); 129 | PrintLevel(subNode->right,level-1); 130 | } 131 | } 132 | bool Search(Node *subNode,const Object& item){ 133 | if(subNode == NULL) return false; 134 | if(subNode->data == item) return true; 135 | if(item < subNode->data) return Search(subNode->left,item); 136 | else return Search(subNode->right,item); 137 | } 138 | public: 139 | AVL(){ 140 | root = NULL; 141 | } 142 | bool isEmpty()const{ 143 | return root == NULL; 144 | } 145 | void Add(const Object& item){ 146 | root = SearchAndAdd(root,item); 147 | } 148 | void inorder(){ 149 | inorder(root); 150 | } 151 | void preorder(){ 152 | preorder(root); 153 | } 154 | void postorder(){ 155 | postorder(root); 156 | } 157 | void levelorder(){ 158 | int h = Height(); 159 | for(int level=0;level<=h;level++){ 160 | PrintLevel(root,level); 161 | } 162 | } 163 | int Height(){ 164 | return Height(root); 165 | } 166 | bool Search(const Object& item){ 167 | return Search(root,item); 168 | } 169 | void Clear(){ 170 | while(!isEmpty()) DeleteNode(root); 171 | } 172 | ~AVL(){ 173 | Clear(); 174 | } 175 | }; 176 | 177 | #endif 178 | -------------------------------------------------------------------------------- /Week9/ArrayBSTTree/include/BST.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BST_HPP 2 | #define BST_HPP 3 | 4 | #include 5 | #include 6 | #define SIZE 5000 7 | 8 | using namespace std; 9 | 10 | template 11 | class BST{ 12 | private: 13 | Object *items; 14 | int IndexFill[SIZE]; 15 | 16 | int FindIndex(const Object& item,int currentIndex=0){ 17 | while(true){ 18 | if(IndexFill[currentIndex] == 0 || currentIndex == SIZE){ 19 | return -1; 20 | } 21 | if(items[currentIndex] == item && IndexFill[currentIndex] == 1) 22 | return currentIndex; 23 | else if(item < items[currentIndex]) currentIndex = 2*currentIndex+1; 24 | else if(item > items[currentIndex]) currentIndex = 2*currentIndex+2; 25 | 26 | } 27 | } 28 | bool IsPowerOfTwo(int x){ 29 | while(((x%2) == 0 ) && x > 1) x/=2; 30 | return (x==1); 31 | } 32 | int MinValue(int i=0){ 33 | if(2*i+1 > SIZE) return i; 34 | else if(IndexFill[2*i+1] == 0) return i; 35 | else return MinValue(2*i+1); 36 | } 37 | public: 38 | BST(){ 39 | items = new Object[SIZE]; 40 | clear(); 41 | } 42 | void clear(){ 43 | for(int i=0;i items[currentIndex]) currentIndex = 2*currentIndex+2; 57 | else return; 58 | } 59 | } 60 | bool find(const Object& item){ 61 | if(FindIndex(item) == -1) return false; 62 | return true; 63 | } 64 | int Height(int index=0){ 65 | if(IndexFill[index] == 0) return -1; 66 | return 1+max(Height(2*index+1),Height(2*index+2)); 67 | } 68 | void inorder(int index=0){ 69 | if(index < SIZE && IndexFill[index] != 0){ 70 | inorder(2*index+1); 71 | cout<