llist.h

来自「设计一个类库」· C头文件 代码 · 共 69 行

H
69
字号
#ifndef LLIST_H
#define LLIST_H
// Double-Linked List implementation

#include"link.h"

class LList{
private:
	Link* head;
	Link* tail;
	Link* fence;
	int leftcnt;
	int rightcnt;
	void init(){
		fence = tail = head = new Link;
		leftcnt = rightcnt = 0;
	}
	void removeall(){
		while ( head != NULL ){
			fence = head;
			head = head->next;
			delete fence;
		}
	}
	
public:
	LList (){ init(); }
	~LList() { removeall();}
	void clear(){  removeall(); init(); }
	bool insert(Record&);
	bool append(Record&);
	bool remove(Record&);
	
	//set functions;
	void setStart(){
		fence = head;
		rightcnt +=leftcnt;
		leftcnt = 0;
	}
	
	void setEnd(){
		fence = tail; 
		leftcnt +=rightcnt;
		rightcnt = 0;
	}
	
	void prev();
	void next(){
		if( fence != tail ){
			fence = fence-> next;
		    rightcnt--;
			leftcnt++;
		}
	}
	
	int leftLenth()  const { return leftcnt; }
	int rightLenth() const { return rightcnt;}
	
	bool setPos(int pos);
	
	Record& getValue(void) const{
			return fence->next->rec;
	}

};

#endif

⌨️ 快捷键说明

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