Link table data structure list.h

xiaoxiao2021-03-06  103

///

///

// Link table data structure list.h //

///

//

#include

Template

Class List;

Template

Class ListNode

{

PUBLIC:

Friend Class List ;

Private:

TYPE DATA;

ListNode * next;

}

Template

Class List

{

PUBLIC:

List ();

~ List ();

Void Insert (Type); / / Insert an element to the tail of the linked list

BOOL INSERT (Type, int); / / Insert an element in any position to the linked list

Void Delnode (INT i); // Delete Elements

INT FIND (Type T); // Find elements

void makeempty (); // destroyed list

Bool print (); // Printing list

INT getlen (); // Get the length of the linked list

Private:

ListNode * first, * last;

Int length;

}

Template

Void InitList (Type & TMP);

Template

Void List_Exit (List & l, type tmp);

Void initation ();

Template

Void List_inSertend (List & l, type tmp);

Template int list :: getlen ()

{

Return Length;

}

Template void list :: makeempty ()

{

ListNode * p1, * p2;

P1 = first-> next;

First-> next = NULL;

While (p1! = null)

{

P2 = P1;

P1 = p1-> next;

Delete P2;

}

Length = 0;

}

Template void list :: Insert (Type T)

{

ListNode * p;

P = new listNode ;

P-> DATA = T;

P-> Next = NULL;

Last-> next = p;

Last = P;

Length ;

}

Template bool list :: insert (Type T, INT i)

{

ListNode * p;

p = first;

INT K = 1;

While (p! = NULL && K

{

P = P-> next;

K ;

}

IF (p == NULL && K! = i)

Return False;

Else

{

ListNode * tp;

TP = New ListNode ;

TP-> DATA = T;

TP-> next = p-> next; p-> next = TP;

Length ;

Return True;

}

}

Template void list :: delNode (INT i)

{

INT k = 1;

ListNode * p, * t;

p = first;

While (P-> Next! = NULL && K! = i)

{

P = P-> next;

K ;

}

T = p-> next;

Cout << "You have already deleted the data item << t-> data <<" "delete" << ENDL;

P-> Next = P-> Next-> next;

Length -;

Delete T;

}

Template Bool List :: print ()

{

ListNode * p = first-> next;

IF (Length == 0)

Return False;

Else

{

There is "<< length <<" item data in the COUT << "Link:" << ENDL;

While (p)

{

Cout << P-> Data << "

P = P-> next;

}

}

Cout << Endl;

Return True;

}

Template int list :: Find (Type T)

{

ListNode * p = first-> next;

INT i = 1;

While (P && P-> Data! = T)

{

P = P-> next;

i ;

}

IF (p)

Return I;

Else

Return 0;

}

Template list :: ~ list ()

{

DELETE FIRST;

Cout << "Welcome to use (! ^!)" << Endl;

}

Template list :: list ()

{

ListNode * node = new listNode ;

Node-> next = NULL;

First = last = node;

Length = 0;

}

转载请注明原文地址:https://www.9cbs.com/read-102111.html

New Post(0)