C ++ version-linked list

Source: Internet
Author: User

# Include "head. H"
# Include "iostream. H"
# Include "string. H"

Typedef char elemtype;

Typedef struct lnode {
Elemtype data;
Struct lnode * next;
} Lnode, * link;

Class linklist
{
PRIVATE:
Link head;
Public:
Linklist (){}
Linklist (elemtype A []);
Void createlinklist ();
Void inver ();
Elemtype get (int I );
Status insert (INT Loc, elemtype E );
Elemtype del (int I );
Void print ();
Void mergelist (linklist la, linklist lb );
};
Linklist: linklist (elemtype A [])
{
Int n = strlen (a), I;
Link P;
Head = new lnode;
Head-> next = NULL;
For (I = n-1; I> = 0; I --)
{
P = new lnode;
P-> DATA = A [I];
P-> next = head-> next;
Head-> next = P;
}
};
Void linklist: Print ()
{
Link P = head-> next;
While (P)
{
Cout <p-> data <"-> ";
P = p-> next;
}
Cout <"null" <Endl;
};
Void linklist: createlinklist ()
{
Int N;
Cout <"Enter the length of the table you want to build :";
Cin> N;
Elemtype * E;
E = new elemtype [N];
Cin> E;
Int I;
Link P;
Head = new lnode;
Head-> next = NULL;
For (I = n-1; I> = 0; I --)
{
P = new lnode;
P-> DATA = E [I];
P-> next = head-> next;
Head-> next = P;
}

}
Elemtype linklist: Get (int I)
{
Int CNT = 1;
Link P = head-> next;
While (CNT! = I)
P = p-> next;
Return p-> data;

}
Status linklist: insert (INT Loc, elemtype E)
{
Link P = head;
Int J = 0;
While (P & J ++ <loc-1) P = p-> next;
If (! P | j> loc-1) return error;
Link S = new lnode;
S-> DATA = E;
S-> next = p-> next;
P-> next = s;
Return OK;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.