#ifndef _LINK_H_
#define _LINK_H_
class List
{
public:
List();
~List();
void insert(const int d1);
void tail_insert(const int d1);
void insert_pos(const int d1,const int d);
void remove(const int d1);
void reverse();
void print() const;
int search(const int d1,const int d);
private:
struct Node
{
int data;
struct Node *next;
};
struct Node *head;
};
#endif
#include <iostream>
#include "List.h"
#include <cstdlib>
using namespace std;
List :: List()
{
head = new Node();
head -> next = NULL;
}
List :: ~List()
{
Node *p = head -> next;
while(p != NULL)
{
head -> next = p -> next;
delete p;
p = head -> next;
}
delete head;
head = NULL;
}
//从头插入一个结点
void List:: insert(const int d1)
{
Node *p = new Node();
p ->