You are on page 1of 9

1:#include<iostream>

2:usingnamespacestd;
3:
4:typedefstructlist
5:{
6:intvalue;
7:structlist*pass;
8:}element;
9:
10:list*foundNode=NULL;
11:boolisEmpty(list*l)
12:{
13:if(l==NULL)
14:{
15:returntrue;
16:}
17:else
18:returnfalse;
19:}
20:
21:voidinsertHead(list*&l,intx)
22:{
23:list*newNode=newelement();
24:newNode>value=x;
25:newNode>pass=l;
26:l=newNode;
27:}
28:
29:voidswapp(list*&l)
30:{
31:list*found1;
32:list*head=l;
33:while(head>value!=44)
34:{
35:found1=head;
36:head=head>pass;
37:}
38:list*before1=found1;
39:list*after1=head;
40:
41:
42:head=l;

Page 1

43:list*found2;
44:while(head>value!=88)
45:{
46:found2=head;
47:head=head>pass;
48:}
49:list*before2=found2;
50:list*after2=head;
51:
52:
53:list*temp;
54:temp=before1>pass;
55:before1>pass=before2>pass;
56:before2>pass=temp;
57:
58:
59:temp=after2>pass;
60:after2>pass=after1>pass;
61:after1>pass=temp;
62:}
63:
64:intlistLength(list*&l)
65:{
66:list*head=l>pass;
67:intx=head>value;
68:list*sh=l;
69:intsasia=0;
70:while(sh)
71:{
72:sasia++;
73:sh=sh>pass;
74:}
75:returnsasia;
76:}
77:
78:voidprint(list*l)
79:{
80:list*temp=l;
81:while(temp!=NULL)
82:{
83:cout<<""<<temp>value<<">"<<"";
84:temp=temp>pass;

Page 2

85:}
86:cout<<"NULL"<<endl;
87:}
88:
89:voidsearchNode(list*&l,intn)
90:{
91:inti=1;
92:boolflag=false;
93:list*cur=l;
94:while(cur)
95:{
96:if(cur>value==n)
97:{
98:cout<<"Elementindodhetnehallkene:"<<i<<endl;
99:flag=true;
100:foundNode=cur;
101:break;
102:}
103:i++;
104:cur=cur>pass;
105:}
106:if(!flag)
107:{
108:cout<<"Elementinukgjendetneliste"<<endl;
109:}
110:}
111:
112:voidaddNodeLast(list*head,intn)
113:{
114:list*newNode=newlist();
115:newNode>value=n;
116:newNode>pass=NULL;
117:
118:list*cur=head;
119:while(cur)
120:{
121:if(cur>pass==NULL)
122:{
123:cur>pass=newNode;
124:return;
125:}
126:cur=cur>pass;

Page 3

127:}
128:}
129:
130:intlistToInt(list*&l)
131:{
132:list*head=l;
133:intn=0;
134:floati=0.1;
135:while(head)
136:{
137:n=n+head>value*static_cast<int>(i*10);
138:head=head>pass;
139:i*=10;
140:}
141:
142:returnn;
143:}
144:
145:voidIntToList(intn,list*&shuma)
146:{
147:if(n<1)
148:{
149:return;
150:}
151:else
152:{
153:addNodeLast(shuma,n%10);
154:}
155:IntToList(n/10,shuma);
156:}
157:
158:voidmaxToEnd(list*&l)
159:{
160:list*max=l;
161:list*temp=l>pass;
162:list*head=l;
163:list*found;
164:while(temp)
165:{
166:if(max>value<temp>value)
167:{
168:max=temp;

Page 4

169:found=max;
170:}
171:temp=temp>pass;
172:}
173:temp=l;
174:if(max>pass==NULL)
175:{
176:return;
177:}
178:
179:elseif(max==l)
180:{
181:l=l>pass;
182:}
183:
184:else
185:{
186:while(temp>pass!=max)
187:{
188:temp=temp>pass;
189:}
190:temp>pass=max>pass;
191:}
192:
193:while(temp>pass!=NULL)
194:{
195:temp=temp>pass;
196:}
197:temp>pass=max;
198:max>pass=NULL;
199:}
200:
201:voidminToHead(list*&l)
202:{
203:list*head=l;
204:list*min=l;
205:list*temp=l>pass;
206:while(temp)
207:{
208:if(temp>value<min>value)
209:{
210:min=temp;

Page 5

211:}
212:temp=temp>pass;
213:}
214:temp=l;
215:if(min==l)
216:{
217:return;
218:}
219:elseif(min>pass!=NULL)
220:{
221:temp=l;
222:while(temp>pass!=min)
223:{
224:temp=temp>pass;
225:}
226:temp=NULL;
227:}
228:else
229:{
230:while(temp>pass!=min)
231:{
232:temp=temp>pass;
233:}
234:temp>pass=min>pass;
235:}
236:
237:head=l;
238:min>pass=head;
239:l=min;
240:
241:}
242:
243:voidswappTest(list*&l,inta,intb)
244:{
245:list*found1;
246:list*head=l;
247:searchNode(l,a);
248:list*firstNode=foundNode;
249:while(head!=firstNode)
250:{
251:found1=head;
252:head=head>pass;

Page 6

253:}
254:list*before1=found1;
255:list*after1=head;
256:
257:
258:head=l;
259:list*found2;
260:searchNode(l,b);
261:list*secondNode=foundNode;
262:while(head!=secondNode)
263:{
264:found2=head;
265:head=head>pass;
266:}
267:list*before2=found2;
268:list*after2=head;
269:
270:
271:list*temp;
272:temp=before1>pass;
273:before1>pass=before2>pass;
274:before2>pass=temp;
275:
276:
277:temp=after2>pass;
278:after2>pass=after1>pass;
279:after1>pass=temp;
280:}
281:
282:voidchangeOdd(list*&l)
283:{
284:inti=0;
285:list*temp=l;
286:list*head=temp;
287:for(i=0;i<listLength(l)/2;i++)
288:{
289:head=temp;
290:for(intj=0;j<listLength(l);j++)
291:{
292:temp=temp>pass;
293:if(j%2==0&&j!=0)
294:{

Page 7

295:head=temp;
296:intx=temp>value;
297:head=head>pass;
298:inty=head>value;
299:swappTest(l,x,y);
300:}
301:}
302:
303:}
304:}
305:
306:intmain()
307:{
308:list*l;
309:list*eliri=newelement();
310:eliri>value=44;
311:eliri>pass=NULL;
312:l=eliri;
313:
314:eliri=newelement();
315:eliri>value=9;
316:eliri>pass=NULL;
317:l>pass=eliri;
318:
319:eliri=newelement();
320:eliri>value=55;
321:eliri>pass=NULL;
322:l>pass=eliri;
323:print(l);
324:addNodeLast(l,32);
325:print(l);
326:addNodeLast(l,26);
327:print(l);
328:cout<<isEmpty(l)<<endl;
329:insertHead(l,200);
330:addNodeLast(l,88);
331:print(l);
332:searchNode(l,66);
333:searchNode(l,72);
334:maxToEnd(l);
335:print(l);
336:print(l);

Page 8

337:addNodeLast(l,7);
338:print(l);
339:minToHead(l);
340:print(l);
341:swappTest(l,44,88);
342:print(l);
343:
344:list*num1;
345:eliri=newelement();
346:eliri>value=9;
347:eliri>pass=NULL;
348:num1=eliri;
349:
350:addNodeLast(num1,1);
351:addNodeLast(num1,5);
352:cout<<listToInt(num1);
353:print(num1);
354:
355:list*num2=newelement();
356:addNodeLast(num2,1);
357:addNodeLast(num2,5);
358:cout<<listToInt(num2);
359:print(num2);
360:
361:ints=listToInt(num2)+listToInt(num1);
362:cout<<"shuma"<<s<<endl;
363:list*shuma=newelement();
364:IntToList(s,shuma);
365:print(shuma);
366:
367:changeOdd(l);
368:print(l);
369:return0;
370:}

Page 9