C + + sequential list (stack/queue, etc.) ADT

Source: Internet
Author: User

#include <iostream>using namespacestd;//ADTtemplate<classT>classseqlist{ Public:        //constructor FunctionSeqlist () { This->length =0; This->data =NULL;} Seqlist (intlength); Seqlist (intlength,t array[]); //Increase        intPush (T data);//Enter (Stack/team) and return the length of the new array        intUnshift (T data);//similar to queue, enter from team header, and return the length of the new array//DeleteT pop ();//out of the stack and returns the element valueT shift ();//out of the team and return the element value at the//Check        intLength ();//returns the array length        BOOLIncludes (T data);//queries whether the element exists in the array        intIndexOf (T data);//returns the subscript for this valueT ValueOf (intindex);//returns the value corresponding to the subscript//(fix) ChangeT replacevalueof (intindex);//Replace the value with the subscript and return the original value at that point        intReplaceindexof (T data);//Follow//Sort        voidSort ();//Default ascending order        voidSortintTYPE);//0: Ascending, 1 reverse//Reverse        voidreverse (); ~seqlist (); Private: T*data; intlength;}; Template<classT>seqlist<t>::seqlist (intlength) {    if(length>-1){         This->length =length;  This->data =NewT[length]; }Else{        Throw "warning:argument ' length ' is invalid!"; }}template<classT>seqlist<t>::seqlist (intlength,t array[]) {    if(length>-1){         This->length =length;  This->data =NewT[length]; }Else{        Throw "warning:argument ' length ' is invalid!"; }         for(intI=0;i< This->length;i++){         This->data[i] =Array[i]; } printf ("Constructor has completed!"); } //Enter (Stack/team) and return the length of the new arraytemplate<classT>intSeqlist<t>::p ush (T data) {return 0; }//similar to queue, enter from team header, and return the length of the new arraytemplate<classT>intSeqlist<t>:: Unshift (T data) {return 0;}//out of the stack and returns the element valuetemplate<classT>T seqlist<T>::p op () {}//out of the team and return the element value at thetemplate<classT>T seqlist<T>:: Shift () {}template<classT>intSeqlist<t>::length () {//returns the array length    return  This-length;} Template<classT>BOOLSeqlist<t>::includes (T data) {//queries whether the element exists in the array    return true;} Template<classT>intSeqlist<t>::indexof (T data) {//returns the subscript for this value    return 0;} Template<classT>T seqlist<t>::valueof (intIndex) {//returns the value corresponding to the subscript    returnNULL;}//(fix) Changetemplate<classT>T seqlist<t>::replacevalueof (intIndex) {//Replace the value with the subscript and return the original value at that point    returnNULL;} Template<classT>intSeqlist<t>::replaceindexof (T data) {//Follow    return 0;}//Sorttemplate<classT>voidSeqlist<t>::sort () {//Default ascending order    ;} Template<classT>voidSeqlist<t>::sort (intTYPE) {//0: Ascending, 1 reverse    ; } //Reversetemplate<classT>voidSeqlist<t>:: Reverse () {;} Template<classT>seqlist<t>::~seqlist () {Delete[] This-data;} intMain () {seqlist<int>demo (2); cout<<Demo.        Length (); return 0;}

C + + sequential list (stack/queue, etc.) ADT

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.