linklist.h

来自「数据库课程设计 导航 其实就是Dijkstra算法的应用」· C头文件 代码 · 共 100 行

H
100
字号
#include "iostream.h"
enum compare{BIG,SMALL};
template <class ElementType>
struct LinkListNode
{
  ElementType value;
  LinkListNode   *next;
};
template <class Type>
class LHList
{
 private:
	 int count;
    LinkListNode<Type>  *head;   
	LinkListNode<Type>  *tail;   
 public:
	 LHList();
    ~LHList();
    bool  isEmpty();   //Judge the List is empty or not. 
    bool appendNode(Type item); //在后面追加 
	void clear();
	void printList();
	void printNode(char symbol);
};
template <class Type>
LHList<Type>::LHList()
{
count=0;
head=NULL;
tail=NULL;
}
template <class Type>
LHList<Type>::~LHList()
{
  clear();
}

template <class Type>
void LHList<Type>::clear()
{
    LinkListNode<Type> *temp;
    while(head!=NULL)
	{
		temp=head;
	    head=head->next;
        delete temp;
	}
	count=0;
	head=NULL;
	tail=NULL;
}
template <class Type>
void LHList<Type>::printList()
{
   LinkListNode<Type> *temp=head;
   while(temp!=NULL)
	{
		cout<<temp->value->symbol<<"."<<temp->value->name<<" ";
	    temp=temp->next; 
	}
   cout<<endl;
}
  
template <class Type>
bool LHList<Type>::appendNode(Type item)
{
   LinkListNode<Type> *node=new LinkListNode<Type> ;
   if(node!=NULL)
   {
     node->value=item;
     node->next=NULL;
     if(head==NULL)  head=node; 
     else tail->next=node; 
     tail=node;
     count++; 
	 return true;
   }
   return false;
}
template <class Type>
void LHList<Type>::printNode(char symbol)
{
   LinkListNode<Type> *temp=head;
   while(temp!=NULL)
	{
	   if(temp->value->symbol==symbol)
	   {
		 cout<<"代号:"<<temp->value->symbol<<"\t"
			 <<"名称:"<<temp->value->name<<endl
			 <<"简介:"<<temp->value->brief
			 <<endl;
       return;
	   }
	    temp=temp->next; 
	}
   cout<<"你输入的代号不正确!";
}
  
  

⌨️ 快捷键说明

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