⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.cpp

📁 做为linux下图形用户界面支持系统之一的MicroWindows采用C++设计
💻 CPP
字号:
//
// Micro Windows Implementation
// list.cpp: list implementation
//
// $Revision: 1.1 $
// $Source: P:/MWINDOWS/LIB/rcs/list.cpp $
// $Date: 1993/10/03 03:45:14 $
//
#include "list.h"

List::List ()
{
    head = new ListNode;
    tail = new ListNode;

    head->prev = head;
    head->next = tail;

    tail->prev = head;
    tail->next = tail;

    current = head;
}

List::~List ()
{
    purge();
    delete head;
    delete tail;
}

BOOL List::put (Object *obj)
{
    ListNode *newNode = new ListNode (obj, current, current->next);

    current->next->prev = newNode;
    current->next = newNode;
    current = newNode;

    return (TRUE);
}

BOOL List::hasElement (Object *obj)
{
    ListNode *n = head;

    while ((n = n->next) != tail) if (n == obj) return (TRUE);
    return (FALSE);
}

void List::purge ()
{
    ListNode *n = head->next, *b;

    while (1)
    {
        if (n == tail) break;
        b = n->next;
        delete n;
        n = b;
    }

    head->next = tail;
    tail->prev = head;
}

BOOL List::isEmpty ()
{
    if (head->next == tail) return (TRUE);
    return (FALSE);
}

Object *List::first ()
{
    if ((current = head->next) == tail) current = head;
    return (current->obj);
}

Object *List::next ()
{
    if (current->next == tail) return (NULL);
    current = current->next;
    return (current->obj);
}

Object *List::last ()
{
    current = tail->prev;
    return (current->obj);
}

Object *List::previous ()
{
    if (current->prev == head) return (NULL);
    current = current->prev;
    return (current->obj);
}

BOOL List::remove ()
{
    if (current == head) return (FALSE);

    current->prev->next = current->next;
    current->next->prev = current->prev;

    ListNode *cp = current->prev;

    delete current;
    current = cp;
    if (current == head) first();

    return (TRUE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -