柚子快报激活码778899分享:[C++]线性链表之单链表
[文档整理系列] 线性链表之单链表
/*
问题描述:线性表____链表_____单链表
@date 2017-3-7
*/
#include
using namespace std;
template
struct node{
T data;
node
};
template
class LinkedList{
public:
LinkedList();
LinkedList(T arr[],int n);
~LinkedList();
int getLength();
void InsertAt(int n,T data);
T DeleteAt(int i);
T GetData(int i);
int getDataAt(T data);
void Print();
private:
int length;
node
};
template
LinkedList
first = new node
first->next = NULL;
length = 0;
}
template
LinkedList
first = new node
first->next = NULL;
for(int i = 0;i node s.data = arr[i]; s.next = first->next; first->next = &s; } length = n; cout<<"初始化成功!"< } template LinkedList node while (first) //释放单链表的每一个结点的存储空间 { q=first; //暂存被释放结点 first=first->next; //工作指针p指向被释放结点的下一个结点,使单链表不断开 delete q; } cout<<"析构(销毁)成功!"< } template int LinkedList return length; } template< typename T> void LinkedList cout<<"成功插入第"< } int main(){ int arr[6]={7,19,4,5,6,9}; LinkedList // t.InsertAt(7,689); return 0; } 柚子快报激活码778899分享:[C++]线性链表之单链表 参考链接
发表评论