From 8931781e0d6dc4bfb9aa52762a465cb973b5693a Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Mon, 3 Aug 2026 02:33:30 +0300 Subject: [PATCH] complete generic linked list implementation Finish the pending SLinkedList implementation for chapter 3. Fixes #1 --- .../GenericLinkedList/SLinkedList.cpp | 16 ++++++++-------- .../linked_list/GenericLinkedList/SLinkedList.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/chapter_3/linked_list/GenericLinkedList/SLinkedList.cpp b/chapter_3/linked_list/GenericLinkedList/SLinkedList.cpp index c4265c6..2447a51 100644 --- a/chapter_3/linked_list/GenericLinkedList/SLinkedList.cpp +++ b/chapter_3/linked_list/GenericLinkedList/SLinkedList.cpp @@ -15,19 +15,19 @@ SLinkedList::~SLinkedList() { template -bool SLinkedList::empty() const { +bool SLinkedList::empty() const { return head == NULL; } template -const E& SLinkedList::front() const { +const E& SLinkedList::front() const { return head -> ele; } template -void SLinkedList::addFront(const E& e) { - SNode* v = new SNode; +void SLinkedList::addFront(const E& e) { + SNode* v = new SNode; v -> ele = e; v -> next = head; head = v; @@ -35,15 +35,15 @@ void SLinkedList::addFront(const E& e) { template -void removeFront() { - SNode* old = head; +void SLinkedList::removeFront() { + SNode* old = head; head = head -> next; delete old; } template -void printList() { - SNode* temp = new SNode; +void SLinkedList::printList() { + SNode* temp = new SNode; temp = head; while(temp != NULL) { cout << temp -> ele << "\n"; diff --git a/chapter_3/linked_list/GenericLinkedList/SLinkedList.h b/chapter_3/linked_list/GenericLinkedList/SLinkedList.h index 02c5233..4a803df 100644 --- a/chapter_3/linked_list/GenericLinkedList/SLinkedList.h +++ b/chapter_3/linked_list/GenericLinkedList/SLinkedList.h @@ -20,8 +20,8 @@ class SLinkedList { SLinkedList(); ~SLinkedList(); bool empty() const; - const & front() const; - void addFront(const & e); + const E& front() const; + void addFront(const E& e); void removeFront(); void printList(); };