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

📄 list.cpp

📁 使用TEA加密方法的简单加密解密程序. 包含 COMMAND版本 和 WIN32 两个版本.可供初学者学习. 超级雷电
💻 CPP
字号:
#include <io.h>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <cstring>
#include "list.h"

using namespace std;

List::List()
{
    file = NULL;
    len = 0;
}

List::~List()
{
    Node* p = file;
    Node* tp;
    while (p) {
        tp = p;
        p = p->next;
        delete tp;
    }
}

void List::init()
{
    Node* p = file;
    Node* tp;
    while (p) {
        tp = p;
        p = p->next;
        delete tp;
    }
    file = NULL;
    len = 0;
}    
    

int List::getlen()
{
    return len;
}

bool List::add(const char* dir)
{
    Node* p = file;
    Node* np;
    
    if (!(np = new Node)) return false;
    strcpy(np->name, dir);
    np->next = NULL;
    
    if (p == NULL) file = np;
    else {
        while (p->next) p = p->next;
        p->next = np;
    }
    len++;
    return true;
}

char* List::get(int n)
{
    Node* p = file;
    
    if (n > getlen() || n <= 0) return NULL;
    for (int i = 1; i < n; i++) p = p->next;
    return p->name;
}    

void List::disfile()
{
    int i = 0;
    Node* p = file;
    cout<<"┌【文件】┐"<<endl;
    cout<<"┌──────────────────────────────────────┐";
    while (p) {
        i++;
        char fdir[_MAX_PATH];
        sprintf(fdir, "  [%2d][%-30.30s] ", i, p->name);
        cout<<fdir;
        if (i % 2 == 0) cout<<endl;
        p = p->next;
    }
    if (i % 2 != 0) cout<<endl;
    cout<<"└──────────────────────────────────────┘";
}

void List::dissub(int len)
{
    int i = 0;
    Node* p = file;
    cout<<"┌【子目录】┐"<<endl;
    cout<<"┌──────────────────────────────────────┐";
    while (p) {
        i++;
        char fdir[_MAX_PATH];
        sprintf(fdir, "  [%2d][%-30.30s] ", i+len, p->name);
        cout<<fdir;
        if (i % 2 == 0) cout<<endl;
        p = p->next;
    }
    if (i % 2 != 0) cout<<endl;
    cout<<"└──────────────────────────────────────┘";
}

char* List::gettop()
{
    int i = 0;
    Node *p = file;
    Node *pp = NULL;
    
    if (p == NULL) return NULL;
    while (p->next) {
        pp = p;
        p = p->next;
    }
    strcpy(temp, p->name);
    if (len == 1) file = NULL;
    else pp->next = NULL;
    delete p;
    len--;
    return temp;
}    

bool List::reinit(const char *dir, int n)
{
    Node* p = file;
    Node* tp;
    while (p) {
        tp = p;
        p = p->next;
        delete tp;
    }
    file = NULL;
    len = 0;
    
    char deDir[_MAX_PATH];
    int i = 0, j = 0, k = 0;
    while (i < strlen(dir)) {
        while (dir[i++] != '\\');
        if (dir[i] == '\0') break;
        for (j = 0; j < i; j++) deDir[j] = dir[j];
        deDir[j] = '\0';
        if (!add(deDir)) return false; 
        if (++k == n) break;
    }
    
    return true;
}    
        
        
        
        
            
                
            

⌨️ 快捷键说明

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