-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathList.c
926 lines (772 loc) · 27.3 KB
/
List.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
/*
* List.c - doubly linked list library
*
* DESCRIPTION
* This module contains routines to create and maintain doubly linked
* lists of data objects. A list can be used for storing data object
* pointers or integer values (except zero).
*
* The application using this library only has to deal with a single list
* pointer and its data objects. It does not have to deal with list nodes
* as is often seen, neither do the the data objects need to supply space
* for list pointers (often called <pNext> and <pPrev>). This list type
* is generally called to be 'non-intrusive'.
* The price paid for this convenience is that nodes can not be accessed
* randomly, which means that deleting a node may require a linear search.
* The list does however keeps a pointer to the last accessed list node;
* the supplied set of operations relative to this node still makes this
* kind of list very useful for many applications without (much) perfor-
* mance loss compared to 'more traditional' linked lists in C.
*
* NOTES
* Doing something that is not allowed, or entering a condition that is
* regarded as an error, will result in a 'failed assertion', when this
* module has been built with DEBUG defined. The routine descriptions
* tell what to watch out for.
*
* INTERNAL
* The idea of using a dummy node was taken from "Obfuscated C and Other
* Mysteries" by Don Libes, John Wiley & Sons - 1993, chapter 11. It
* results in simpler list operation code.
*
* down--> <--up
* after--> <--before
*
* +-------------------- - --------------+
* | |
* +--------------+ V Head Node Tail Node |
* | | +-------+ +-------+ +-------+ |
* | pHead---------->|/pNext------>| pNext---- - -->| pNext----+
* | | |///////| | | | |
* | pNodeLast--->? +----pPrev/|<------pPrev |<- - -----pPrev |
* | | | |///////| | | | |
* | count | | |/pData/| | pData | +->| pData |
* | | | +-- | --+ +-- | --+ | +-- | --+
* +--------------+ | | | | |
* | V V | V
* | ### ### | ###
* //// = Dummy Node | ### ### | ###
* | |
* ### = User Data +--------------------------- - +
*
* Notice that pList->pHead->pPrev points to the tail of the list; this
* is used a number of times in the code below.
*
* For efficiency some short code fragments show up a number of times
* in different routines, instead of nesting the routines.
*
* INCLUDE FILES
* List.h
*
* COPYRIGHT
* You are free to use, copy or modify this software at your own risk.
*
* AUTHOR
* Cornelis van der Bent. Please let me know if you have comments or find
* flaws: [email protected]. Enjoy!
*
* MODIFICATION HISTORY
* 1999/04/12 vdbent Thorough test and debugging; beta release.
* 1999/03/09 kees Composed.
*
*****************************************************************************/
#include <stdlib.h>
#include "List.h"
#include "Assert.h" /* includes "Except.h" which defines return() macro */
/******************************************************************************
*
* ListCreate - create empty list
*
* DESCRIPTION
* This routine creates an empty list.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Pointer to empty list.
*/
List * ListCreate(void)
{
List * pList;
pList = malloc(sizeof(List));
pList->pHead = malloc(sizeof(ListNode));
pList->pHead->pNext = pList->pHead->pPrev = pList->pHead;
pList->pNodeLast = NULL;
pList->count = 0;
return pList;
}
/******************************************************************************
*
* ListDestroy - free list but not user data
*
* DESCRIPTION
* This routine frees the list handle and the nodes, but does not free
* the user data.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* N/A.
*/
void ListDestroy(
List * pList) /* pointer to list */
{
ListNode * pNode;
assert(pList != NULL);
pNode = pList->pHead->pNext;
while (pNode != pList->pHead)
{
ListNode * pNext;
pNext = pNode->pNext;
free(pNode);
pNode = pNext;
}
free(pList->pHead);
free(pList);
}
/******************************************************************************
*
* ListDestroyData - free list including user data
*
* DESCRIPTION
* This routine frees the list handle and the nodes, and does also free
* the user data using free(); the caller is responsible that all of this
* user data was allocated with routines compatible with free().
*
* SIDE EFFECTS
* None.
*
* RETURNS
* N/A.
*/
void ListDestroyData(
List * pList) /* pointer to list */
{
ListNode * pNode;
assert(pList != NULL);
pNode = pList->pHead->pNext;
while (pNode != pList->pHead)
{
ListNode * pNext;
pNext = pNode->pNext;
free(pNode->pData);
free(pNode);
pNode = pNext;
}
free(pList->pHead);
free(pList);
}
/******************************************************************************
*
* ListAddHead - add node to head of list
*
* DESCRIPTION
* This routine adds the specified data object value at the head of the
* specified list. The last accessed list node is set to the added
* node.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* N/A.
*/
void ListAddHead(
List * pList, /* pointer to list */
void * pData) /* data object value */
{
ListNode * pNode;
assert(pList != NULL);
pNode = malloc(sizeof(ListNode));
pNode->pData = pData;
(pNode->pNext = pList->pHead->pNext)->pPrev = pNode;
(pList->pHead->pNext = pNode)->pPrev = pList->pHead;
pList->pNodeLast = pNode;
pList->count++;
}
/******************************************************************************
*
* ListAddTail - add node to tail of list
*
* DESCRIPTION
* This routine adds the specified data object value at the tail of the
* specified list. The last accessed list node is set to the added
* node.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* N/A.
*/
void ListAddTail(
List * pList, /* pointer to list */
void * pData) /* data object value */
{
ListNode * pNode;
assert(pList != NULL);
pNode = malloc(sizeof(ListNode));
pNode->pData = pData;
(pNode->pPrev = pList->pHead->pPrev)->pNext = pNode;
(pList->pHead->pPrev = pNode)->pNext = pList->pHead;
pList->pNodeLast = pNode;
pList->count++;
}
/******************************************************************************
*
* ListAddBefore - add node before last accessed node
*
* DESCRIPTION
* This routine adds the specified data object value in the specified
* list just before the node that was last accessed by one of the
* routines from this library that set it. 'Before' means towards the
* head of the list. The last accessed list node is set to the added
* node.
*
* Nothing happens when the last accessed list node is not set; this
* causes a failed assertion when DEBUG defined.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* N/A.
*/
void ListAddBefore(
List * pList, /* pointer to list */
void * pData) /* data object value */
{
ListNode * pNode;
assert(pList != NULL);
validate(pList->pNodeLast != NULL, NOTHING);
pNode = malloc(sizeof(ListNode));
pNode->pData = pData;
(pNode->pPrev = pList->pNodeLast->pPrev)->pNext = pNode;
(pList->pNodeLast->pPrev = pNode)->pNext = pList->pNodeLast;
pList->pNodeLast = pNode;
pList->count++;
}
/******************************************************************************
*
* ListAddAfter - add node after last accessed node
*
* DESCRIPTION
* This routine adds the specified data object value in the specified
* list right after the node that was last accessed by one of the
* routines from this library that set it. 'After' means towards the
* tail of the list. The last accessed list node is set to the added
* node.
*
* Nothing happens when the last accessed list node is not set; this
* causes a failed assertion when DEBUG defined.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* N/A.
*/
void ListAddAfter(
List * pList, /* pointer to list */
void * pData) /* data object value */
{
ListNode * pNode;
assert(pList != NULL);
validate(pList->pNodeLast != NULL, NOTHING);
pNode = malloc(sizeof(ListNode));
pNode->pData = pData;
(pNode->pNext = pList->pNodeLast->pNext)->pPrev = pNode;
(pList->pNodeLast->pNext = pNode)->pPrev = pList->pNodeLast;
pList->pNodeLast = pNode;
pList->count++;
}
/******************************************************************************
*
* ListRemoveHead - remove head node from list
*
* DESCRIPTION
* This routine removes the head list node from the specified list. The
* last accessed list node is reset.
*
* It is not allowed to pass this routine an empty list.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Removed data object value.
*/
void * ListRemoveHead(
List * pList) /* pointer to list */
{
void * pData;
ListNode * pNode;
assert(pList != NULL);
validate(pList->count > 0, NULL);
pNode = pList->pHead->pNext;
pData = pNode->pData;
(pList->pHead->pNext = pNode->pNext)->pPrev = pList->pHead;
free(pNode);
pList->pNodeLast = NULL;
pList->count--;
return pData;
}
/******************************************************************************
*
* ListRemoveTail - remove tail node from list
*
* DESCRIPTION
* This routine removes the tail list node from the specified list. The
* last accessed list node is reset.
*
* It is not allowed to pass this routine an empty list.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Removed data object value.
*/
void * ListRemoveTail(
List * pList) /* pointer to list */
{
void * pData;
ListNode * pNode;
assert(pList != NULL);
validate(pList->count > 0, NULL);
pNode = pList->pHead->pPrev;
pData = pNode->pData;
(pList->pHead->pPrev = pNode->pPrev)->pNext = pList->pHead;
free(pNode);
pList->pNodeLast = NULL;
pList->count--;
return pData;
}
/******************************************************************************
*
* ListRemove - remove specified node from list
*
* DESCRIPTION
* This routine removes the node with the specified data object value
* The last accessed list node is reset.
*
* It is an error if the specified node is not in the list. It is not
* allowed to pass this routine an empty list.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Removed data object value.
*/
void * ListRemove(
List * pList, /* pointer to list */
void * pData) /* data object value */
{
ListNode * pNode;
assert(pList != NULL);
validate(pList->count > 0, NULL);
pNode = pList->pHead->pNext;
while (pNode != pList->pHead && pNode->pData != pData)
pNode = pNode->pNext;
validate(pNode->pData == pData, NULL);
pNode->pNext->pPrev = pNode->pPrev;
pNode->pPrev->pNext = pNode->pNext;
free(pNode);
pList->pNodeLast = NULL;
pList->count--;
return pData;
}
/******************************************************************************
*
* ListRemoveLast - remove last accessed node from list
*
* DESCRIPTION
* This routine removes the node which was last accessed by one of the
* routines in this library that set it. Subsequently the last accessed
* list node is set to the next node for convenience.
*
* It is an error if the last accessed node was not set by one of the
* routines in this library. It is not allowed to pass this routine an
* empty list.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Removed data object value.
*/
void * ListRemoveLast(
List * pList) /* pointer to list */
{
void * pData;
ListNode * pNext;
assert(pList != NULL);
validate(pList->pNodeLast != NULL, NULL);
pData = pList->pNodeLast->pData;
pNext = pList->pNodeLast->pNext;
pList->pNodeLast->pNext->pPrev = pList->pNodeLast->pPrev;
pList->pNodeLast->pPrev->pNext = pList->pNodeLast->pNext;
free(pList->pNodeLast);
pList->pNodeLast = pNext;
pList->count--;
return pData;
}
/******************************************************************************
*
* ListHead - get head data object value
*
* DESCRIPTION
* This routine returns the user data object value of the head node of
* the specified list. The last accessed list node is reset if the list
* is empty, otherwise it is set to the list head.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Head data object value, or NULL if empty.
*/
void * ListHead(
List * pList) /* pointer to list */
{
assert(pList != NULL);
if (pList->count == 0)
return NULL;
else
return 0, (pList->pNodeLast = pList->pHead->pNext)->pData;
}
/******************************************************************************
*
* ListTail - get tail data object value
*
* DESCRIPTION
* This routine returns the user data object value of the tail node of
* the specified list. The last accessed list node is reset if the list
* is empty, otherwise it is set to the list tail.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Head data object value, or NULL if empty.
*/
void * ListTail(
List * pList) /* pointer to list */
{
assert(pList != NULL);
if (pList->count == 0)
return NULL;
else
return 0, (pList->pNodeLast = pList->pHead->pPrev)->pData;
}
/******************************************************************************
*
* ListLast - get last accessed data object value
*
* DESCRIPTION
* This routine returns the user data object value of the last accessed
* node of the specified list. The last accessed list node is not
* affected.
*
* When the last accessed list node is not set, which is also the case
* when the list is empty, NULL is returned.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Last accessed data object value, or NULL if not set.
*/
void * ListLast(
List * pList) /* pointer to list */
{
assert(pList != NULL);
if (pList->pNodeLast == NULL)
return NULL;
else
return pList->pNodeLast->pData;
}
/******************************************************************************
*
* ListNext - get next data object value
*
* DESCRIPTION
* This routine returns the user data object value of the next node
* with respect to the last accessed list node. The last accessed list
* node is set to the next node, or is reset if the tail is passed.
*
* It is an error if the last accessed list node is not set; which is
* also the case when the list is empty.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Next data object value, or NULL if already at tail.
*/
void * ListNext(
List * pList) /* pointer to list */
{
assert(pList != NULL);
validate(pList->pNodeLast != NULL, NULL);
if ((pList->pNodeLast = pList->pNodeLast->pNext) == pList->pHead)
{
pList->pNodeLast = NULL;
return NULL;
}
else
return pList->pNodeLast->pData;
}
/******************************************************************************
*
* ListPrev - get previous data object value
*
* DESCRIPTION
* This routine returns the user data object value of the previous node
* with respect to the last accessed list node. The last accessed list
* node is set to the previous node, or is reset if the head is passed.
*
* It is an error if the last accessed list node is not set; which is
* also the case when the list is empty.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Next data object value, or NULL if already at head.
*/
void * ListPrev(
List * pList) /* pointer to list */
{
assert(pList != NULL);
validate(pList->pNodeLast != NULL, NULL);
if ((pList->pNodeLast = pList->pNodeLast->pPrev) == pList->pHead)
{
pList->pNodeLast = NULL;
return NULL;
}
else
return pList->pNodeLast->pData;
}
/******************************************************************************
*
* ListCount - report number of nodes in list
*
* DESCRIPTION
* This routine returns the number of nodes in the specified list.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Number of nodes in list.
*/
int ListCount(
List * pList) /* pointer to list */
{
assert(pList != NULL);
return pList->count;
}
/******************************************************************************
*
* ListFind - find list node
*
* DESCRIPTION
* This routine finds the node with the specified data object value. If
* nothing was found the last accessed list node is not affected,
* otherwise it is set to the found node.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Found data object value, or NULL if not found or empty list.
*/
void * ListFind(
List * pList, /* pointer to list */
void * pData) /* data object value */
{
ListNode * pNode;
assert(pList != NULL);
pNode = pList->pHead->pNext;
while (pNode != pList->pHead && pNode->pData != pData)
pNode = pNode->pNext;
if (pNode->pData == pData)
{
pList->pNodeLast = pNode;
return pData;
}
else
return NULL;
}
/******************************************************************************
*
* ListSplitBefore - split list just before last node
*
* DESCRIPTION
* This routine splits up the specified list in two parts. The split is
* made just before the last accessed list node. A new list is created
* for the part before the last accessed node. The last accessed list
* node for the original list is not affected. And the last accessed
* list node for the new list is reset.
*
* It is not allowed to pass this routine an empty list. If the list
* contains only one node, the new list will be empty.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Pointer to new list containing nodes before original last accessed
* list node.
*/
List * ListSplitBefore(
List * pListOrg) /* pointer to original list */
{
List * pListNew;
ListNode * pNodeOrg;
assert(pListOrg != NULL);
validate(pListOrg->count > 0, NULL);
validate(pListOrg->pNodeLast != NULL, NULL);
pListNew = malloc(sizeof(List));
pListNew->pHead = malloc(sizeof(ListNode));
pListNew->pHead->pData = NULL;
pListNew->count = 0;
pNodeOrg = pListOrg->pHead->pNext;
while (pNodeOrg != pListOrg->pNodeLast)
{
pListOrg->count--;
pListNew->count++;
pNodeOrg = pNodeOrg->pNext;
}
if (pListNew->count == 0)
{
pListNew->pHead->pPrev = pListNew->pHead->pNext = pListNew->pHead;
}
else
{
/* connect list part to new list */
pListNew->pHead->pNext = pListOrg->pHead->pNext;
pListNew->pHead->pNext->pPrev = pListNew->pHead;
pListNew->pHead->pPrev = pListOrg->pNodeLast->pPrev;
pListNew->pHead->pPrev->pNext = pListNew->pHead;
/* bind last accessed node and original dummy node together */
pListOrg->pHead->pNext = pListOrg->pNodeLast;
pListOrg->pNodeLast->pPrev = pListOrg->pHead;
}
pListNew->pNodeLast = NULL;
return pListNew;
}
/******************************************************************************
*
* ListSplitAfter - split list just after last node
*
* DESCRIPTION
* This routine splits up the specified list in two parts. The split is
* made just after the last accessed list node. A new list is created
* for the part after the last accessed node. The last accessed list
* node for the original list is not affected. And the last accessed
* list node for the new list is reset.
*
* It is not allowed to pass this routine an empty list. If the list
* contains only one node, the new list will be empty.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Pointer to new list containing nodes after original last accessed
* list node.
*/
List * ListSplitAfter(
List * pListOrg) /* pointer to original list */
{
List * pListNew;
ListNode * pNodeOrg;
assert(pListOrg != NULL);
validate(pListOrg->count > 0, NULL);
validate(pListOrg->pNodeLast != NULL, NULL);
pListNew = malloc(sizeof(List));
pListNew->pHead = malloc(sizeof(ListNode));
pListNew->pHead->pData = NULL;
pListNew->count = 0;
pNodeOrg = pListOrg->pNodeLast->pNext;
while (pNodeOrg != pListOrg->pHead)
{
pListOrg->count--;
pListNew->count++;
pNodeOrg = pNodeOrg->pNext;
}
if (pListNew->count == 0)
{
pListNew->pHead->pPrev = pListNew->pHead->pNext = pListNew->pHead;
}
else
{
/* connect list part to new list */
pListNew->pHead->pNext = pListOrg->pNodeLast->pNext;
pListNew->pHead->pNext->pPrev = pListNew->pHead;
pListNew->pHead->pPrev = pListOrg->pHead->pPrev;
pListNew->pHead->pPrev->pNext = pListNew->pHead;
/* bind last accessed node and original dummy node together */
pListOrg->pNodeLast->pNext = pListOrg->pHead;
pListOrg->pHead->pPrev = pListOrg->pNodeLast;
}
pListNew->pNodeLast = NULL;
return pListNew;
}
/******************************************************************************
*
* ListConcat - concatenate two lists
*
* DESCRIPTION
* This routine concatenates the second list <pListAdd> to the tail of
* the first list <pListDst>. Either list (or both) may be empty. After
* the operation the <pListAdd> handle is destroyed. The last accessed
* list node of the resulting list is reset.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* List pointer <pListDst> containing the nodes of both lists.
*/
List * ListConcat(
List * pListDst, /* pointer to destination list */
List * pListAdd) /* pointer to list to be added at tail */
{
assert(pListDst != NULL);
assert(pListAdd != NULL);
switch (((pListAdd->count > 0) << 1) | (pListDst->count > 0))
{
case 0:
/* both lists empty */
break;
case 1:
/* destination list not empty and add list empty */
break;
case 2:
/* destination list empty and add list not empty */
pListDst->pHead->pNext = pListAdd->pHead->pNext;
pListDst->pHead->pNext->pPrev = pListDst->pHead;
pListDst->pHead->pPrev = pListAdd->pHead->pPrev;
pListDst->pHead->pPrev->pNext = pListDst->pHead;
break;
case 3:
/* both lists not empty */
pListAdd->pHead->pPrev->pNext = pListDst->pHead;
pListDst->pHead->pPrev->pNext = pListAdd->pHead->pNext;
pListAdd->pHead->pNext->pPrev = pListDst->pHead->pPrev;
pListDst->pHead->pPrev = pListAdd->pHead->pPrev;
break;
}
pListDst->pNodeLast = NULL;
pListDst->count += pListAdd->count;
free(pListAdd->pHead);
free(pListAdd);
return pListDst;
}
/* end of List.c */