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.
LinkedList.h
00001 /** 00002 * @file LinkedList.h 00003 * @brief Core Utility - Templated Linked List class 00004 * @author sam grove 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2013 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 #ifndef LINKEDLIST_H_ 00024 #define LINKEDLIST_H_ 00025 00026 #include <stdint.h> 00027 #include "mbed.h" 00028 00029 /** 00030 * @struct node 00031 * @brief The Linked List structure 00032 */ 00033 struct node 00034 { 00035 void *data ; /*!< pointer to list member data */ 00036 struct node *next ; /*!< pointer to the next list member */ 00037 }; 00038 00039 /** Example using the LinkedList Class 00040 * @code 00041 * #include "mbed.h" 00042 * #include "LinkedList.h" 00043 * 00044 * LinkedList<node>list; 00045 * 00046 * int main() 00047 * { 00048 * node *tmp; 00049 * 00050 * list.push((char *)"Two\n"); 00051 * list.append((char *)"Three\n"); 00052 * list.append((char *)"Four\n"); 00053 * list.push((char*)"One\n"); 00054 * list.append((char*)"Five\n"); 00055 * 00056 * for(int i=1; i<=list.length(); i++) 00057 * { 00058 * tmp = list.pop(i); 00059 * printf("%s", (char *)tmp->data); 00060 * } 00061 * 00062 * error("done\n"); 00063 * } 00064 * @endcode 00065 */ 00066 00067 /** 00068 * @class LinkedList 00069 * @brief API abstraction for a Linked List 00070 */ 00071 template<class retT> 00072 class LinkedList 00073 { 00074 protected: 00075 retT *_head; 00076 00077 public: 00078 /** Create the LinkedList object 00079 */ 00080 LinkedList(); 00081 00082 /** Deconstructor for the LinkedList object 00083 * Removes any members 00084 */ 00085 ~LinkedList(); 00086 00087 /** Add a member to the begining of the list 00088 * @param data - Some data type that is added to the list 00089 * @return The member that was just inserted (NULL if empty) 00090 */ 00091 retT *push(void *data); 00092 00093 // /** Add a member to some position in the list 00094 // * @param data - Some data type that is added to the list 00095 // * @param loc - Place in the list to put the data 00096 // * @return The member that was just inserted (NULL if empty) 00097 // */ 00098 // retT *insert(void *data, uint32_t loc); 00099 00100 /** Add a member to the end of the list 00101 * @param data - Some data type that is added to the list 00102 * @return The member that was just inserted (NULL if empty) 00103 */ 00104 retT *append(void *data); 00105 00106 /** Remove a member from the list 00107 * @param loc - The location of the member to remove 00108 * @return The head of the list 00109 */ 00110 retT *remove(uint32_t loc); 00111 00112 /** Get access to a member from the list 00113 * @param loc - The location of the member to access 00114 * @return The member that was just requested (NULL if empty or out of bounds) 00115 */ 00116 retT *pop(uint32_t loc); 00117 00118 /** Get the length of the list 00119 * @return The number of members in the list 00120 */ 00121 uint32_t length(void); 00122 }; 00123 00124 #endif /* LINKEDLIST_H_ */
Generated on Wed Aug 17 2022 05:29:14 by
1.7.2