C++实现单链表数据结构
myList.h
#ifndef MYLIST_H
#define MYLIST_H
typedef struct node
{
int data;
struct node *next;
}Node;
class myList
{
public:
myList();
~myList();
void initList(); // 初始化单链表
int getData(int pos); //得到pos位置的元素
void insert(int val, int pos); //将值为val的元素插入到单链表的pos位置
int remove(int pos); //删除第pos个结点,并返回该结点的值
void reverse(); //对单链表进行转置
int searchValue(int val); //寻找值为val的结点在单链表中的位置
int getLength(); //返回单链表的长度
void print(); //遍历打印单链表
private:
Node *head; //头结点指针
Node *cur; //当前结点指针
int length; //单链表长度
};
#endif
myList.cpp
#include &