Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.0 KiB

  1. /*
  2. *
  3. * NOTES:
  4. *
  5. * REVISIONS:
  6. * pcy14Dec92: Changed Sortable to ApcSortable
  7. * ane11Jan93: Reassign theHead in Add when appropriate
  8. * jps14Jul94: added stdlib.h for os2
  9. *
  10. */
  11. #define INCL_BASE
  12. #define INCL_NOPM
  13. #include "cdefine.h"
  14. extern "C"
  15. {
  16. #if (C_OS & C_OS2)
  17. #include <stdlib.h>
  18. #endif
  19. #include <string.h>
  20. }
  21. #include "slist.h"
  22. #include "sortable.h"
  23. //------------------------------------------------------------------------
  24. SortedList:: SortedList() : List()
  25. {
  26. }
  27. //------------------------------------------------------------------------
  28. void SortedList::Add( RApcSortable anObject )
  29. {
  30. if (theHead == (PNode)NULL)
  31. {
  32. theHead = new Node( &anObject);
  33. theTail = theHead;
  34. }
  35. else
  36. {
  37. INT Done = FALSE;
  38. PNode current = GetHeadNode();
  39. PNode previous = current->GetPrev(); // This shouldbe NULL
  40. while (!Done)
  41. {
  42. PApcSortable sortobj = (PApcSortable)current->GetData();
  43. if ( sortobj->LessThan(&anObject) )
  44. {
  45. previous = current;
  46. current = previous->GetNext();
  47. if (!current) // At the end
  48. Done = TRUE;
  49. }
  50. else
  51. {
  52. Done = TRUE;
  53. }
  54. }
  55. PNode temp = new Node( &anObject, current, previous);
  56. if (current)
  57. current->SetPrev(temp);
  58. if (previous) // Just in case you are adding to the head
  59. previous->SetNext(temp);
  60. else
  61. theHead = temp;
  62. }
  63. theItemsInContainer++;
  64. }
  65. //------------------------------------------------------------------------
  66. ProtectedSortedList::ProtectedSortedList() : ProtectedList()
  67. {
  68. }
  69. //------------------------------------------------------------------------
  70. void ProtectedSortedList::Add( RApcSortable anObject )
  71. {
  72. Request();
  73. if (theHead == (PNode)NULL)
  74. {
  75. theHead = new Node( &anObject);
  76. theTail = theHead;
  77. }
  78. else
  79. {
  80. INT Done = FALSE;
  81. PNode current = GetHeadNode();
  82. PNode previous = current->GetPrev(); // This shouldbe NULL
  83. while (!Done)
  84. {
  85. PApcSortable sortobj = (PApcSortable)current->GetData();
  86. if ( sortobj->LessThan(&anObject) )
  87. {
  88. previous = current;
  89. current = previous->GetNext();
  90. if (!current) // At the end
  91. Done = TRUE;
  92. }
  93. else
  94. {
  95. Done = TRUE;
  96. }
  97. }
  98. PNode temp = new Node( &anObject, current, previous);
  99. if (current)
  100. current->SetPrev(temp);
  101. if (previous) // Just in case you are adding to the head
  102. previous->SetNext(temp);
  103. else
  104. theHead = temp;
  105. }
  106. theItemsInContainer++;
  107. Clear();
  108. }