5好用了

This commit is contained in:
iridiumR 2021-10-23 10:54:30 +08:00
parent 2e8fe9fbb8
commit 06731225c0
2 changed files with 31 additions and 25 deletions

View file

@ -43,7 +43,7 @@ Node List::succInsert(Node Old, int New)
T->pred = Old; T->pred = Old;
T->succ = Old->succ; T->succ = Old->succ;
Old->succ = T; Old->succ = T;
T->pred->succ = T; T->succ->pred = T;
_size++; _size++;
return T; return T;
} }
@ -85,7 +85,7 @@ Node List::succInsertN(Node Old, Node New)
T->pred = Old; T->pred = Old;
T->succ = Old->succ; T->succ = Old->succ;
Old->succ = T; Old->succ = T;
T->pred->succ = T; T->succ->pred = T;
_size++; _size++;
return T; return T;
} }
@ -144,25 +144,26 @@ void List::removeN(Node i)
_size--; _size--;
} }
Node List::searchN(int value, int n, Node p)
{
while (0 <= n--)
if (((p = p->pred)->data) <= value)
break;
return p;
}
void List::sort() void List::sort()
{ {
int sorted = 0; Node p=first();
Node p; for (int r = 0; r < _size; r++)
for (int i = 0; i <= _size - 1 - sorted; i++) {
for (int j = i; j <= _size - 1 - sorted; j++) succInsert(searchN(p->data,r,p),p->data);
{ p=p->succ;
int max = 0; removeN(p->pred);
Node maxN; }
}
p = find(j);
if (max < p->data) int List::valid(Node p)
{ {
max = p->data; return p && (trailer != p) && (header != p);
maxN = p;
}
maxN->data = p->data;
p->data = max;
sorted++;
}
} }

View file

@ -17,6 +17,12 @@ private:
int _size; int _size;
protected: protected:
Node firstInsertN(Node New);
Node lastInsertN(Node New);
Node succInsertN(Node old, Node ne);
Node predInsertN(Node old, Node ne);
void removeN(Node i);
Node searchN(int value,int n,Node p);
public: public:
int getSize() int getSize()
@ -32,14 +38,13 @@ public:
void lastInsert(int New); void lastInsert(int New);
Node succInsert(Node Old, int New); Node succInsert(Node Old, int New);
Node predInsert(Node Old, int New); Node predInsert(Node Old, int New);
Node firstInsertN(Node New);
Node lastInsertN(Node New);
Node succInsertN(Node old, Node ne);
Node predInsertN(Node old, Node ne);
int get(int i); int get(int i);
Node find(int i); Node find(int i);
int remove(int i); int remove(int i);
void removeN(Node i); Node searchN(int value,int n);
int valid(Node p);
void sort(); void sort();