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

📄 linklist.h

📁 基于正向最大匹配法的分词。采用hash表技术将一段连续的话用所给词库进行分词输出。
💻 H
字号:
#ifndef LINKLIST_H
#define LINKLIST_H
#include<string>
#include<fstream>
#include<iostream>
using namespace std;
struct snode                //链表中节点类型的声明
{string data;
snode* next;
};
class linklist              //链表类声明
{private:
        snode* head;        //链表头指针
public:
	linklist(){head=NULL;}   //初始化空链表
    void insert(string a);
	void del(string a);
	string search(string b,int n);	
};

void linklist::insert(string a)      //向链表尾添加节点的函数
{snode* newp=new snode;
newp->data=a;
newp->next=NULL;
if(head==NULL)  head=newp;
else {snode* p=head;
      while(p->next!=NULL) p=p->next;
	  p->next=newp;
     }
}
string linklist::search(string b,int n)    //在链表中返回string b前向匹配的最大字符串
{ string temp;
  for(int i=n;i>=2;i=i-2)              //最小比配字符串长度为2,即单个字
     { temp=b.substr(0,i);            
      snode* q=head;
	  while(q!=NULL)
	  {if(q->data==temp)             //在链表中搜索匹配串
	    return temp;
	   q=q->next;   
	  }
     }
return temp;                          //返回匹配串
}
void linklist::del(string a)         //删除链表中所有数据元素为string a的函数
{snode *p=head,*q=NULL;
   while(p!=NULL)
   { if(p->data==a)                 //删除数据元素为a的节点,并对p,q重新赋值
      { if(q==NULL) head=p->next;
        else q->next=p->next;
		delete p;
       if(q==NULL) p=head;
		else p=q->next;
      }
   else{ q=p;
	     p=p->next;           //p,q右移一位
       }
   }   
}
#endif

⌨️ 快捷键说明

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