📄 list.h
字号:
#include <iostream.h>
#include "node.h"
class linklist
{
private:
node* head;
node* pcurrent;
public:
linklist();
node* haddr();
node* pcaddr();
void insertbefore(const int& item);
void insertafter(const int& item);
void del();
void result();
};
linklist::linklist()
{
//
head=new node(-1,NULL);
pcurrent=head;
}
void linklist::insertbefore(const int& item)
{
node* p=head;
node* s;
if(head->next==NULL)
{
node* p=new node(item,NULL);
head->next=p;
pcurrent=p;
}
else
{
while(p->next!=pcurrent)
p=p->next;
s=new node(item,pcurrent);
p->next=s;
pcurrent=s;
}
}
void linklist::insertafter(const int& item)
{
node*p=new node(item,pcurrent->next);
pcurrent->next=p;
pcurrent=p;
}
void linklist::del()
{
if(head->next==NULL)
cout<<"no element left"<<endl;
else
{
node*p=head;
while(p->next!=pcurrent)
p=p->next;
p->next=pcurrent->next;
delete pcurrent;
pcurrent=p->next;
}
}
node* linklist::haddr()
{
return head;
}
node* linklist::pcaddr()
{
return pcurrent;
}
void linklist::result()
{
node* p=head->next;
while(p!=NULL)
{
cout<<p->data<<"\n";
p=p->next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -