summaryrefslogtreecommitdiff
path: root/lib/PLList.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PLList.cc')
-rw-r--r--lib/PLList.cc126
1 files changed, 126 insertions, 0 deletions
diff --git a/lib/PLList.cc b/lib/PLList.cc
new file mode 100644
index 0000000..5234b91
--- /dev/null
+++ b/lib/PLList.cc
@@ -0,0 +1,126 @@
+#include <stdio.h>
+#include "config.h"
+#include "PLList.h"
+
+
+PriorityList *PLList::Union(PriorityList * P)
+{
+ if ((P->GetType()) != (((PriorityList *) this)->GetType())) {
+ return GenericUnion(P);
+ } else {
+ CList *x, *y, *t;
+ PLList *T = ((PLList *) P);
+
+ x = &Head;
+ y = T->Head.Right;
+ Key += T->Key;
+
+ while (x->Right && y) {
+ if (x->Right->Key > y->Key) {
+ t = y->Right;
+ y->Right = x->Right;
+ y->Left = x;
+ x->Right->Left = y;
+ x->Right = y;
+ y = t;
+ }
+ x = x->Right;
+ }
+
+ if (y) {
+ x->Right = y;
+ y->Left = x;
+ }
+
+ T->Head.Right = NULL;
+ }
+ return this;
+}
+
+bool PLList::Lower_Key(Cell x, Key_t NKey)
+{
+ CList *T = ((CList *) x), *t;
+
+ if (T->Key < NKey)
+ return false;
+
+ T->Key = NKey;
+
+ if (T->Left)
+ T->Left->Right = T->Right;
+ if (T->Right)
+ T->Right->Left = T->Left;
+
+ for (t = T->Left; ((t->Left->Left) && (NKey < t->Left->Key));
+ t = t->Left) ;
+
+ T->Left = t->Left;
+ T->Right = t;
+ t->Left = T->Left->Right = T;
+ return true;
+}
+
+
+PLList::PLList(void)
+{
+ type = T_PLLIST;
+ Key = 0;
+ Datas = NULL;
+};
+PLList::~PLList(void)
+{
+ delete Head.Right;
+};
+
+Key_t PLList::ReadKey(Cell C)
+{
+ return Head.ReadKey(C);
+};
+Datas_t PLList::ReadDatas(Cell C)
+{
+ return Head.ReadDatas(C);
+};
+int PLList::rn(void)
+{
+ int n = 0;
+
+ for (CList * x = Head.Right; x; x = x->Right)
+ n++;
+ return n;
+}
+
+void PLList::Dump(ostream & os)
+{
+ os << _(" * Head cell\n |\n");
+ for (CList * x = Head.Right; x; x = x->Right)
+ os << " |__ " << x->Key << endl;
+}
+
+bool PLList::IsEmpty(void)
+{
+ return (!(Head.Right));
+}
+
+Cell PLList::Min(void)
+{
+ return Head.Right;
+}
+
+Cell PLList::Insert(Key_t IKey, Datas_t const &IDatas)
+{
+ Key++;
+ return Head.Insert(IKey, IDatas);
+}
+
+Key_t PLList::Extract_Min(Datas_t & Datas)
+{
+ if (!Key)
+ exception(4, _("Extract_Min: Priority List is empty."));
+ Key--;
+ return Head.Delete(Datas, Head.Right);
+}
+
+Key_t PLList::Delete(Datas_t & Datas, Cell x)
+{
+ return Head.Delete(Datas, x);
+}