题目:实现一个递增排序的单链表(不允许重复),即每次向链表中插入一个或多个元素后都能保证链表仍是递增有序的,在此基础上实现一些基本操作,如插入元素、清空元素、判断两个链表是否相等及查找某个指定的元素。
为了实现该功能,首先定义一个头文件linked_list.h声明单链表的基本操作:
#ifndef LINKED_LIST_H_
#define LINKED_LIST_H_
#define _INVALID 0xFFFFFFFF
class linked_list {
// value
unsigned int data;
// pointer to the next node in list
linked_list *next;
public:
// instantiated a linked list with the element value. If value is not specified
// an empty list is instantiated
linked_list(unsigned int value = _INVALID);
// destructor
~linked_list();
// check if the list is empty
bool empty();
// insert a value into the list.
void insert(unsigned int value);
// insert all the values from list into the current linked list.
void add(linked_list *list);
// get the size of the linked list.
int size();
// is the current set equal to s (does it contains t