柚子快报激活码778899分享:[C++]线性链表之单链表

http://yzkb.51969.com/

[文档整理系列] 线性链表之单链表

/*

问题描述:线性表____链表_____单链表

@date 2017-3-7

*/

#include

using namespace std;

template

struct node{

T data;

node *next;

};

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 *first;

};

template

LinkedList::LinkedList(){

first = new node;

first->next = NULL;

length = 0;

}

template

LinkedList::LinkedList(T arr[],int n){

first = new node(); //初始化指针变量

first->next = NULL;

for(int i = 0;i

node s;

s.data = arr[i];

s.next = first->next;

first->next = &s;

}

length = n;

cout<<"初始化成功!"<

}

template

LinkedList::~LinkedList(){

node *q;

while (first) //释放单链表的每一个结点的存储空间

{

q=first; //暂存被释放结点

first=first->next; //工作指针p指向被释放结点的下一个结点,使单链表不断开

delete q;

}

cout<<"析构(销毁)成功!"<

}

template

int LinkedList::getLength(){

return length;

}

template< typename T>

void LinkedList::InsertAt(int n,T data){

cout<<"成功插入第"<

}

int main(){

int arr[6]={7,19,4,5,6,9};

LinkedList t(arr,6);

// t.InsertAt(7,689);

return 0;

}

  

柚子快报激活码778899分享:[C++]线性链表之单链表

http://yzkb.51969.com/

参考链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。
大家都在看: