diff --git a/CONTRIBUTING.MD b/CONTRIBUTING.MD new file mode 100644 index 0000000..e2c2823 --- /dev/null +++ b/CONTRIBUTING.MD @@ -0,0 +1,9 @@ +# Contributing Guide + +Terima kasih sudah ingin berkontribusi! 🎉 + +1. Fork repo ini. +2. Buat branch baru: `git checkout -b feature-nama`. +3. Commit perubahan dengan pesan jelas. +4. Push ke branch. +5. Buka Pull Request. diff --git a/src/stack.cpp b/src/stack.cpp index 8cea5a3..5997737 100644 --- a/src/stack.cpp +++ b/src/stack.cpp @@ -70,7 +70,6 @@ class Stack{ } }; -#ifndef UNIT_TEST int main(){ Stack stack1(100); stack1.push(1); @@ -83,4 +82,3 @@ int main(){ std::cout << "element paling atas: " << stack1.top() << std::endl; return 0; } -#endif UNIT_TEST \ No newline at end of file diff --git a/src/stack_linked_list.cpp b/src/stack_linked_list.cpp index a87c0b5..f0c5151 100644 --- a/src/stack_linked_list.cpp +++ b/src/stack_linked_list.cpp @@ -50,13 +50,18 @@ class Stack{ head = nullptr; return *this; } - head = new Node(obj.head->data); + //head adalah object saat ini + //obj adalah objek lain yang ingin di copy + head = new Node(obj.head->data); + //isi node pertama yang menunjuk head dengan mengambil dari object lain(ingin di copy) Node* curr = head; + //pakai curr sebagai pointer penunjuk Node* temp = obj.head->next; + //inialisasi temp sebagai pointer untuk mengerakkan obj.head(object lain) while(temp != nullptr){ - curr->next = new Node(temp->data); - curr = curr->next; - temp = temp->next; + curr->next = new Node(temp->data); // insert node dari object lain + curr = curr->next; //jalankan pointer curr + temp = temp->next; //jalankan pointet temp } return *this; } diff --git a/src/stack_templates_implement.cpp b/src/stack_templates_implement.cpp index 15e4cd3..6daf3df 100644 --- a/src/stack_templates_implement.cpp +++ b/src/stack_templates_implement.cpp @@ -39,10 +39,11 @@ class Stack{ //copy constructor Stack(const Stack& obj){ size = obj.size; //supaya tiap object konsisten size yg dimiliki + capacity = obj.capacity; arr = new type[capacity]; //alokasi ulang arr for(size_t i = 0;i < size;i++){ arr[i] = obj.arr[i]; - } + } } Stack& operator=(const Stack& obj){ //this disini menunjuk objek saat ini