Skip to content

Commit

Permalink
Merge pull request #5 from realmarkoprifti/final-oop-approach
Browse files Browse the repository at this point in the history
Added comments
  • Loading branch information
realmarkoprifti authored Oct 4, 2023
2 parents 4a0c3e9 + eeaf256 commit e614996
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/linkedlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ LinkedList::LinkedList(int* numArr, int arrSize, int type)
listType = type;
}


// Automatically frees the list when the object is deconstructured
LinkedList::~LinkedList()
{
ListNode* ptr = head;
Expand All @@ -77,6 +77,7 @@ LinkedList::~LinkedList()
}


// Returns an int containing the lists' length
int LinkedList::length()
{
int length = 0;
Expand All @@ -90,6 +91,7 @@ int LinkedList::length()
}


// Inserts a node at the end of the list
void LinkedList::insert(int val)
{
ListNode* newNode = new ListNode;
Expand Down Expand Up @@ -121,6 +123,7 @@ void LinkedList::insert(int val)
}


// Deletes the first occurrence of a node with the given value
void LinkedList::delNode(int val)
{
ListNode* prev = head;
Expand Down Expand Up @@ -182,6 +185,7 @@ void LinkedList::delNode(int val)
}


// Returns true if the list is sorted
bool LinkedList::isSorted()
{
for (ListNode* ptr = head; ptr != NULL; ptr = ptr->next)
Expand All @@ -199,6 +203,7 @@ bool LinkedList::isSorted()
}


// Sorts the list using the bubble sort algorithm
void LinkedList::sort()
{
/*
Expand Down Expand Up @@ -227,6 +232,7 @@ void LinkedList::sort()
}


// Prints the list's node values
void LinkedList::print()
{
for (ListNode* ptr = head; ptr != NULL; ptr = ptr->next)
Expand All @@ -236,6 +242,7 @@ void LinkedList::print()
}


// Uses Linear Seach to search for a node with the given value. Returns the node if found, else NULL.
ListNode* LinkedList::lsearch(int val)
{
for (ListNode* ptr = head; ptr != NULL; ptr = ptr->next)
Expand Down

0 comments on commit e614996

Please sign in to comment.