Skip to content

Commit b6f4510

Browse files
committed
added unordered euals to doublyll
1 parent 4431075 commit b6f4510

3 files changed

Lines changed: 55 additions & 7 deletions

File tree

DSAdjList/dsadjlist.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ DSDoublyLL<T> DSAdjList<T>::GetConnectedNodes(T nodeData){
117117
return output;
118118
}
119119
}
120+
121+
return DSDoublyLL<T>();
120122
}
121123

122124
/**
@@ -201,7 +203,7 @@ bool DSAdjList<T>::contains(T query)
201203
*/
202204
template <class T>
203205
DSAdjList<T>& DSAdjList<T>::operator=(const DSAdjList<T>& other){
204-
data = other.list;
206+
data = other.data;
205207
}
206208

207209
/**

DSDoublyLL/dsdoublyll.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class DSDoublyLL{
155155
*/
156156
int size() const;
157157

158+
bool unorderedEquals(const DSDoublyLL<T>& other) const;
159+
158160
/**
159161
* @brief DSDoublyLL::operator [] - returns data at passed index
160162
* @param index - index to retrieve data
@@ -560,6 +562,49 @@ int DSDoublyLL<T>::size() const
560562
return numIndexes;
561563
}
562564

565+
template<class T>
566+
bool DSDoublyLL<T>::unorderedEquals(const DSDoublyLL<T> &other) const
567+
{
568+
if(numIndexes != other.numIndexes){
569+
return false;
570+
}
571+
572+
if(numIndexes == 0){
573+
return true;
574+
}
575+
576+
DSDoublyLL<T> temp = other;
577+
578+
// iterate through list1
579+
580+
// if index is in list 2 itterate list 1 and remove from list 2
581+
582+
for(DSNode<T>* i = head; i != nullptr; i = i->next){
583+
DSNode<T>* match = nullptr;
584+
585+
for(DSNode<T>* j = temp.head; j != nullptr; j = j->next){
586+
if(i->data == j->data){
587+
match = j;
588+
break;
589+
}
590+
}
591+
592+
if(match == nullptr){
593+
return false;
594+
}
595+
596+
if(match == temp.head){
597+
temp.head = match->next;
598+
} else{
599+
match->prev->next = match->next;
600+
}
601+
602+
delete match;
603+
}
604+
605+
return true;
606+
}
607+
563608
/**
564609
* @brief DSDoublyLL::operator [] - returns data of node at passed index
565610
* @param index - index to retrieve data

test.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,13 @@ TEST_CASE("Data_Structures_Doubly_Linked_List", "[Doubly_Linked_List][Data_Struc
282282
int arr2StartSize = 3;
283283
const int intArray3[6] = {0, 1, 2, 3, 4, 5};
284284
int arr3StartSize = 6;
285-
286-
const int intArray4[3] = {1,2,4};
285+
const int intArray4[3] = {1, 2, 4};
287286
int arr4StartSize = 3;
287+
const int intArray5[6] = {4, 5, 3, 2, 1, 0};
288+
int arr5StartSize = 6;
288289

289-
DSDoublyLL<int> numList1;
290+
DSDoublyLL<int> numList1, numList2, numList3, numList4, numList5;
290291
DSDoublyLL<int> numList1Copy;
291-
DSDoublyLL<int> numList2;
292-
DSDoublyLL<int> numList3;
293-
DSDoublyLL<int> numList4;
294292

295293
for(int element : intArray1){
296294
numList1.pushBack(element);
@@ -303,6 +301,7 @@ TEST_CASE("Data_Structures_Doubly_Linked_List", "[Doubly_Linked_List][Data_Struc
303301

304302
numList3 = DSDoublyLL<int>(intArray3, arr3StartSize);
305303
numList4 = DSDoublyLL<int>(intArray4, arr4StartSize);
304+
numList5 = DSDoublyLL<int>(intArray5, arr5StartSize);
306305

307306

308307
SECTION("Comparison Operators"){
@@ -317,6 +316,8 @@ TEST_CASE("Data_Structures_Doubly_Linked_List", "[Doubly_Linked_List][Data_Struc
317316
numList1 = numList1Copy;
318317

319318
REQUIRE(numList1 != numList2);
319+
320+
REQUIRE(numList3.unorderedEquals(numList5));
320321
}
321322

322323
SECTION("indexing"){

0 commit comments

Comments
 (0)