FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
linked_list.cpp
1// Copyright 2016-2023 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "linked_list.h"
16
17namespace containers
18{
20 void LinkedListImpl::insert(LinkImpl* item)
21 {
22 item->next_ = head_;
23 head_ = item;
24 }
25
26 bool LinkedListImpl::remove(LinkImpl* item)
27 {
28 if (head_ == nullptr) return false;
29 if (head_ == item)
30 {
31 head_ = head_->next_;
32 item->next_ = nullptr;
33 return true;
34 }
35 LinkImpl* previous = head_;
36 LinkImpl* current = head_->next_;
37 while (current != nullptr)
38 {
39 if (current == item)
40 {
41 previous->next_ = current->next_;
42 item->next_ = nullptr;
43 return true;
44 }
45 previous = current;
46 current = current->next_;
47 }
48 return false;
49 }
51}
Utility API to handle linked list containers.
Contains all FastArduino generic containers:
Definition: array.h:23