跪求一个使用了 类class 的C++动态链表的代码

来源:百度知道 编辑:UC知道 时间:2024/05/12 20:17:25

#ifndef INT_LINKED_LIST
#define INT_LINKED_LIST

class IntSLLNode
{
public:
int info;
IntSLLNode *next;
IntSLLNode (int el,IntSLLNode *ptr = 0)
{
info = el;
next = ptr;
}
};
class IntSLList
{
public:
IntSLList()
{
head = tail = 0;
}
~IntSLList();
int isEmpty()
{
return head == 0;
}
void addToHead(int);
void addToTail(int);
int deleteFromHead();
int deleteFromTail();
void deleteNode(int);
bool isInList(int);
private:
IntSLLNode *head,*tail;
};
#endif

#include <iostream>
#include "intSLLst.h"
using namespace std;

IntSLList::~IntSLList()
{
for(IntSLLNode *p;!isEmpty();)
{
p = head ->next;
delete head;
head = p;
}
}
void IntSLList::addToHead(int el)
{
head = new IntSLLNode(e