/[cvs]/api/Classes/LinkedList/FloatLinkedList.cpp
ViewVC logotype

Annotation of /api/Classes/LinkedList/FloatLinkedList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Sun Jul 1 20:47:58 2001 UTC (23 years ago) by bearsoft
Branch: lazy, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
First import

1 bearsoft 1.1 #include "FloatLinkedList.h"
2     #include "../Sort/FloatLinkedListQuickSort.h"
3     #include "../System/SystemDefine.h"
4    
5     FloatLinkedList::FloatLinkedList()
6     {
7     howfar=0;
8     }
9    
10     ////////////////////////////////////////////////////////////////////////////////////
11     //free memory for all Elements that exsist in the LinkedList
12     ////////////////////////////////////////////////////////////////////////////////////
13    
14     FloatLinkedList::~FloatLinkedList()
15     {
16     removeAllElement();
17     }
18    
19     ////////////////////////////////////////////////////////////////////////////////////
20     //free memory for all Elements that exsist in the LinkedList
21     ////////////////////////////////////////////////////////////////////////////////////
22    
23    
24     void FloatLinkedList::removeAllElement()
25     {
26     if ( howfar != 0 )
27     {
28     FloatElement *element=first;
29    
30     for ( int s=0; s<howfar ; s++ )
31     {
32     FloatElement *tempElement=element->next;
33     delete element;
34     element=tempElement;
35     }
36     }
37     }
38    
39     ////////////////////////////////////////////////////////////////////////////////////
40     //How many Elements is it in the LinkedList
41     ////////////////////////////////////////////////////////////////////////////////////
42    
43     int FloatLinkedList::size()
44     {
45     return howfar;
46     }
47    
48     ////////////////////////////////////////////////////////////////////////////////////
49     //add a Element to the LinkedList
50     ////////////////////////////////////////////////////////////////////////////////////
51    
52    
53     void FloatLinkedList::addLast(float iValue)
54     {
55     if (howfar == 0)
56     {
57     first = new FloatElement(iValue);
58     last=first;
59     }
60     else
61     {
62     last->next = new FloatElement(iValue);
63     last->next->previos=last;
64     last=last->next;
65     }
66    
67     howfar++;
68     }
69    
70     ////////////////////////////////////////////////////////////////////////////////////
71     //get a Element from the LinkedList
72     ////////////////////////////////////////////////////////////////////////////////////
73    
74     float FloatLinkedList::getElement(int step)
75     {
76     FloatElement *element=first;
77    
78     for ( int s=0; s<step ; s++ )
79     {
80     element=element->next;
81     }
82    
83     return element->value;
84     }
85    
86    
87     ////////////////////////////////////////////////////////////////////////////////////
88     //set a Element in the LinkedList
89     ////////////////////////////////////////////////////////////////////////////////////
90    
91     void FloatLinkedList::setElement( float iValue, int index)
92     {
93     if ( index < howfar && index >= 0)
94     {
95     FloatElement *element=first;
96    
97     for ( int s=0; s<index ; s++ )
98     {
99     element=element->next;
100     }
101    
102     element->value=iValue;
103     }
104     }
105    
106     ////////////////////////////////////////////////////////////////////////////////////
107     //sort element in linkedlist
108     ////////////////////////////////////////////////////////////////////////////////////
109    
110     void FloatLinkedList::sortLargestOrder()
111     {
112     FloatLinkedListQuickSort::setStatement(0);
113     FloatLinkedListQuickSort::sortLargestOrder(this,0,howfar-1);
114     }
115    
116     void FloatLinkedList::sortSmallestOrder()
117     {
118     FloatLinkedListQuickSort::setStatement(1);
119     FloatLinkedListQuickSort::sortSmallestOrder(this,0,howfar-1);
120     }
121    
122     ////////////////////////////////////////////////////////////////////////////////////
123     //remove a element from the linkedlist
124     ////////////////////////////////////////////////////////////////////////////////////
125    
126     bool FloatLinkedList::removeElement(int index)
127     {
128     if ( index < howfar && index >= 0)
129     {
130     int temphowfar=howfar;
131     --howfar;
132     FloatElement *lista = first;
133    
134     for ( int w=0; w<index ; w++ )
135     {
136     lista=lista->next;
137     }
138    
139     if ( lista == first && temphowfar == 1 )
140     {
141     delete first;
142     return true;
143     }
144    
145    
146     if ( lista == first && temphowfar != 1 )
147     {
148     bool s=false;
149    
150     if ( lista->next == last )
151     {
152     s=true;
153     }
154    
155     FloatElement *temp=first->next;
156     delete first;
157     first=temp;
158    
159     if (s == true)
160     {
161     last=first;
162     }
163    
164     return true;
165     }
166    
167     if ( lista == last )
168     {
169     FloatElement *temp=last->previos;
170     delete last;
171     last=temp;
172     return true;
173     }
174    
175     int t=0;
176    
177     if ( lista->next == last && lista->previos == first )
178     {
179     t=1;
180     }
181    
182    
183     FloatElement *tempnext=lista->previos;
184     FloatElement *tempprevios=lista->next;
185     delete lista;
186     tempnext->next=tempprevios;
187     tempprevios->previos=tempnext;
188    
189     if ( t == 1 )
190     {
191     first=tempnext;
192     last=tempprevios;
193     }
194    
195     return true;
196     }
197    
198     return false;
199     }

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26