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

📄 linklist.h

📁 数据结构课程设计 数据结构B+树 B+ tree Library
💻 H
字号:
#include "iostream.h"
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);         //在后面追加
    bool deleteNode(int number);       //删除节点 
	bool findNode(int  number);       //查找节点
	bool modifyNode(int number);      //修改节点
	void clear(); 
};
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>
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>
bool LHList<Type>::deleteNode(int number)
{
      LinkListNode<Type> *temp=head;
	  LinkListNode<Type> *p;
	   for(int i=0;i<count;i++)
	   {
		   if(temp->value->number==number)
		   {
		     if(i!=0)
			 {
			  p->next=temp->next;
			  delete temp;
			 }
			 else
			 {
			  head=head->next;
			  delete temp;
			 }
			 count--;
			return true;
		   }
		   p=temp;
	       temp=temp->next;
	   }
	   return false;
}
 

template <class Type>
bool LHList<Type>::findNode(int number)
{
 	  LinkListNode<Type> *temp=head;
	   for(int i=0;i<count;i++)
	   {
		   if(temp->value->number==number)
		   {
		    cout<<"编号:"<<temp->value->number
				<<"\t书名:"<<temp->value->name;
			return true;
		   }
	      temp=temp->next;
	   }
	   return false;
}

template <class Type>
bool LHList<Type>::modifyNode(int number)
{
     LinkListNode<Type> *temp=head;
	   for(int i=0;i<count;i++)
	   {
		   if(temp->value->number==number)
		   {
		      cout<<"原书名:"<<temp->value->name<<"  请输入新书名:"<<endl;
    	      scanf("%s",&(temp->value->name));	 
			  return true;
		   }
	      temp=temp->next;
	   }
	   return false;
}

⌨️ 快捷键说明

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