Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
LinkedListBase.cpp
00001 /* 00002 * Copyright (c) 2018-2019, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "LinkedList.h" 00019 #include "LinkEntry.h" 00020 #include "mbed_assert.h" 00021 00022 LinkedListBase::LinkedListBase(): _head(0), _tail(0) 00023 { 00024 00025 } 00026 00027 LinkedListBase::~LinkedListBase() 00028 { 00029 00030 } 00031 00032 LinkEntry *LinkedListBase::head() 00033 { 00034 return _head; 00035 } 00036 00037 void LinkedListBase::enqueue(LinkEntry *entry) 00038 { 00039 entry->_next = NULL; 00040 if (_tail == NULL) { 00041 _head = entry; 00042 } else { 00043 _tail->_next = entry; 00044 } 00045 _tail = entry; 00046 } 00047 00048 LinkEntry *LinkedListBase::dequeue() 00049 { 00050 if (_head == NULL) { 00051 return NULL; 00052 } 00053 if (_head->_next == NULL) { 00054 _tail = NULL; 00055 } 00056 LinkEntry *entry = _head; 00057 _head = _head->_next; 00058 entry->_next = NULL; 00059 return entry; 00060 } 00061 00062 void LinkedListBase::remove(LinkEntry *entry) 00063 { 00064 LinkEntry *prev = NULL; 00065 LinkEntry *cur = _head; 00066 while (cur != entry) { 00067 if (cur == NULL) { 00068 // Element is not in the list 00069 return; 00070 } 00071 prev = cur; 00072 cur = cur->_next; 00073 } 00074 00075 if (prev != NULL) { 00076 prev->_next = entry->_next; 00077 } 00078 if (entry == _head) { 00079 _head = entry->_next; 00080 } 00081 if (entry == _tail) { 00082 _tail = prev; 00083 } 00084 entry->_next = NULL; 00085 }
Generated on Tue Jul 12 2022 13:54:26 by
