关于Tried树

/*
 * Author: lccccc 
 * Created Time:  2011/11/2 16:22:26
 * File Name: trie.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <stack>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}
struct node{
   char key;
   node* chil[26];
   int ter;
  node(){
    key = 'x';
    for(int i = 0;i < 26;i ++)
       chil[i] = NULL;
   ter = 0;
  }
}; 
void insert(node* root,char* st)
{
    for(int i = 0;i < strlen(st);i ++)
    {
        //cout<<st[i]<<endl;
       if(root->chil[ st[i] - 'a'] == NULL){
           //out("nono");
          node* tm = new node();
          tm->key = st[i];
          root->chil[st[i] - 'a'] = tm;
          root = tm;
       }
       else {
        root = root->chil[ st[i] - 'a'];
       }
    }
    root -> ter = 1;
}
void del(node* root,char* st)
{
    for(int i =  0;i < strlen(st);i ++)
    {
        if( root->chil[ st[i] - 'a'] == NULL)
            return;
        root = root->chil[ st[i] - 'a'];
    }
    if(root->ter == 1) root->ter = 0;
}
bool sear(node* root,char* st)
{
    for(int i = 0;i < strlen(st);i ++)
    {
        if( root->chil[ st[i] - 'a'] == NULL)
            return 0;
        root = root->chil[ st[i] - 'a'];
    }
    if(root->ter) return 1;
    return 0;
}
int main() {
    node* root;
    root = new node();
    cout<<root->key<<endl;
    insert(root,"lcccccc");
    insert(root,"lcxxxxx");
    del(root,"lcccccc");
    cout<<sear(root,"lcccccc")<<endl;
    cout<<sear(root,"lcc")<<endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"All mirrors were tried" 的错误信息表示在尝试下载软件包元数据时,所有的镜像源都尝试过了,但都无法下载。这个错误通常与网络连接问题有关,可能是由于镜像源不可用或网络不稳定导致无法下载软件包元数据。解决这个问题可以尝试以下几种方法: 1. 检查网络连接:确保您的网络连接正常,并且可以访问互联网。您可以尝试打开其他网页或使用其他网络连接来确认网络是否正常工作。 2. 更换镜像源:尝试更换软件包管理器使用的镜像源。镜像源可能因为维护或其他原因而导致不可用。您可以在配置文件中更改镜像源的地址,或者尝试使用其他可靠的镜像源。 3. 清除缓存:有时候缓存文件可能损坏或过期,导致下载失败。您可以尝试清除软件包管理器的缓存,然后再次尝试下载软件包元数据。具体的清除缓存的方法取决于您使用的软件包管理器,可以通过搜索相应的命令找到清除缓存的方法。 4. 检查防火墙设置:防火墙或网络安全设置可能会阻止软件包管理器的访问。请确保防火墙允许软件包管理器的访问, #### 引用[.reference_title] - *1* *2* [centos8 yum安装提示All mirrors were tried](https://blog.csdn.net/bashendixie5/article/details/123156187)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [报Error: Failed to download metadata for repo ‘docker-ce-stable‘: Cannot download repomd.xml:](https://blog.csdn.net/m0_45259293/article/details/119898363)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值