Skip to content

Commit

Permalink
🎨 improved Container functions efficiency/consistency by making them …
Browse files Browse the repository at this point in the history
…all inline functions
  • Loading branch information
habibayman committed Apr 3, 2024
1 parent bc4a7d2 commit 7911f45
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Containers/ArrayStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iostream>
#include "StackADT.h"

// The default size is 100
// The default size is 1000
template<typename T>
class ArrayStack: public StackADT<T>
{
Expand Down
2 changes: 1 addition & 1 deletion Containers/Deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Deque: public LinkedQueue<T>
};

template<typename T>
bool Deque<T>::dequeueBack(T& backEntry)
inline bool Deque<T>::dequeueBack(T& backEntry)
{
if (LinkedQueue<T> ::isEmpty())
return false;
Expand Down
12 changes: 6 additions & 6 deletions Containers/LinkedQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class LinkedQueue: public QueueADT<T>
};

template <typename T>
LinkedQueue<T>::LinkedQueue():itemCount(0), backPtr(nullptr), frontPtr(nullptr)
inline LinkedQueue<T>::LinkedQueue():itemCount(0), backPtr(nullptr), frontPtr(nullptr)
{ }

template <typename T>
bool LinkedQueue<T>::isEmpty() const
inline bool LinkedQueue<T>::isEmpty() const
{
return (frontPtr == nullptr);
}

template <typename T>
bool LinkedQueue<T>::enqueue(const T& newEntry)
inline bool LinkedQueue<T>::enqueue(const T& newEntry)
{
Node<T>* newNodePtr = new Node<T>(newEntry);
// Insert the new node
Expand All @@ -52,7 +52,7 @@ bool LinkedQueue<T>::enqueue(const T& newEntry)
}

template <typename T>
bool LinkedQueue<T>::dequeue(T& frontEntry)
inline bool LinkedQueue<T>::dequeue(T& frontEntry)
{
if (isEmpty())
return false;
Expand All @@ -74,7 +74,7 @@ bool LinkedQueue<T>::dequeue(T& frontEntry)
}

template <typename T>
bool LinkedQueue<T>::peek(T& frontEntry) const
inline bool LinkedQueue<T>::peek(T& frontEntry) const
{
if (isEmpty())
return false;
Expand Down Expand Up @@ -106,7 +106,7 @@ inline int LinkedQueue<T>::getCount() const
}

template <typename T>
LinkedQueue<T>::~LinkedQueue()
inline LinkedQueue<T>::~LinkedQueue()
{
T temp;
while (dequeue(temp));
Expand Down
16 changes: 8 additions & 8 deletions Containers/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ class Node
};

template < typename T>
Node<T>::Node()
inline Node<T>::Node()
: prev(nullptr), next(nullptr)
{ }

template < typename T>
Node<T>::Node(const T& item)
inline Node<T>::Node(const T& item)
: item(item), prev(nullptr), next(nullptr)
{ }

template < typename T>
Node<T>::Node(const T& item, Node<T>* prevNodePtr, Node<T>* nextNodePtr)
inline Node<T>::Node(const T& item, Node<T>* prevNodePtr, Node<T>* nextNodePtr)
: item(item), prev(prevNodePtr), next(nextNodePtr)
{

}
template < typename T>
void Node<T>::setItem(const T& item)
inline void Node<T>::setItem(const T& item)
{
this->item = item;
}

template < typename T>
void Node<T>::setNext(Node<T>* nextNodePtr)
inline void Node<T>::setNext(Node<T>* nextNodePtr)
{
next = nextNodePtr;
}
Expand All @@ -57,19 +57,19 @@ inline void Node<T>::setPrev(Node<T>* prevNodePtr)


template < typename T>
T Node<T>::getItem() const
inline T Node<T>::getItem() const
{
return item;
}

template<typename T>
Node<T>* Node<T>::getPrev() const
inline Node<T>* Node<T>::getPrev() const
{
return prev;
}

template < typename T>
Node<T>* Node<T>::getNext() const
inline Node<T>* Node<T>::getNext() const
{
return next;
}
Expand Down
10 changes: 5 additions & 5 deletions Containers/PriorityNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class PriorityNode
};

template <typename T>
PriorityNode<T>::PriorityNode(const T& _item, int _priority)
inline PriorityNode<T>::PriorityNode(const T& _item, int _priority)
{
setItem(_item, _priority);
next = nullptr;
}

template <typename T>
void PriorityNode<T>::setItem(const T& _item, int _priority)
inline void PriorityNode<T>::setItem(const T& _item, int _priority)
{
item = _item;
priority = _priority;
Expand All @@ -40,21 +40,21 @@ void PriorityNode<T>::setNext(PriorityNode<T>* nextNodePtr)
}

template <typename T>
T PriorityNode<T>::getItem(int& _priority) const
inline T PriorityNode<T>::getItem(int& _priority) const
{
_priority = priority;

return item;
}

template <typename T>
PriorityNode<T>* PriorityNode<T>::getNext() const
inline PriorityNode<T>* PriorityNode<T>::getNext() const
{
return next;
}

template <typename T>
int PriorityNode<T>::getPriority() const
inline int PriorityNode<T>::getPriority() const
{
return priority;
}
Expand Down
16 changes: 8 additions & 8 deletions Containers/PriorityQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class PriorityQueue
};

template <typename T>
PriorityQueue<T>::PriorityQueue(): head(nullptr), itemCount(0)
inline PriorityQueue<T>::PriorityQueue(): head(nullptr), itemCount(0)
{ }

// Insert the new node in its correct position according to its priority
template <typename T>
void PriorityQueue<T>::enqueue(const T& data, int priority)
inline void PriorityQueue<T>::enqueue(const T& data, int priority)
{
PriorityNode<T>* newNode = new PriorityNode<T>(data, priority);

Expand All @@ -53,7 +53,7 @@ void PriorityQueue<T>::enqueue(const T& data, int priority)
}

template <typename T>
bool PriorityQueue<T>::dequeue(T& topEntry, int& pri)
inline bool PriorityQueue<T>::dequeue(T& topEntry, int& pri)
{
if (isEmpty())
return false;
Expand All @@ -68,7 +68,7 @@ bool PriorityQueue<T>::dequeue(T& topEntry, int& pri)
}

template <typename T>
bool PriorityQueue<T>::peek(T& topEntry, int& priority)
inline bool PriorityQueue<T>::peek(T& topEntry, int& priority)
{
if (isEmpty())
return false;
Expand All @@ -80,13 +80,13 @@ bool PriorityQueue<T>::peek(T& topEntry, int& priority)
}

template <typename T>
bool PriorityQueue<T>::isEmpty() const
inline bool PriorityQueue<T>::isEmpty() const
{
return head == nullptr;
}

template <typename T>
void PriorityQueue<T>::printList() const
inline void PriorityQueue<T>::printList() const
{
if (isEmpty()) return;

Expand All @@ -107,13 +107,13 @@ void PriorityQueue<T>::printList() const
}

template <typename T>
int PriorityQueue<T>::getCount() const
inline int PriorityQueue<T>::getCount() const
{
return itemCount;
}

template <typename T>
PriorityQueue<T>::~PriorityQueue()
inline PriorityQueue<T>::~PriorityQueue()
{
T tmp;
int p;
Expand Down

0 comments on commit 7911f45

Please sign in to comment.