One new implementation of single list as below(code: c++):
/**
* Used to create and manage a single linked list of objects of a common
* type. The list of created objects can be examined to find a key by
* an identifier.
*/
1 template <class T, typename K>
2 class objList {
3 protected:
4 static T* objFirst;
5 T* objNext;
6 const K objKey;
7
8 objList(const K key) {
9 objKey = key;
10 objNext = objFirst;
11 objFirst = (T*)this;
12 }
13 public:
14 static T* getObject(const K& key);
15 };
16 template <class T, typename K>
17 T* objList<T, K>::objFirst = NULL;
18
19 template <class T, typename K>
20 objList<T, K>::getObject(const K& key)
21 {
22 T* obj = objList<T, K>::objFirst;
23 while (obj) {
24 if (key==obj->objKey)
25 break;
26 obj = obj->objNext;
27 }
28 return obj;
29 }