(c + +) data structure sequence table coding exercise

Source: Internet
Author: User

List.h#ifndef list_h#define list_hclass list{public:    LIST (int size);    ~list ();    void Clearlist ();    BOOL Listempty ();    int listlength ();    BOOL Getelem (int i,int *e);    int Locateelem (int *e);    BOOL Priorelem (int *currentelem,int *preelem);    BOOL Nextelem (int *currentelem,int *nextelem);    void Listtraverse ();    BOOL Listinsert (int i,int *e);    BOOL Listdelete (int i,int *e);p rivate:    int *m_plist;    int m_isize;    int m_ilength;}; #endif

  

Lsit.cpp#include<list.h> #include <iostream>using namespace std;    list::list (int size) {m_isize = size;    M_plist = new Int[m_isize]; m_ilength = 0;}    List::~list () {delete []m_plist; M_plist = NULL;} void List::clearlist () {m_ilength = 0;} BOOL List::listempty () {return m_ilength = = 0?true:false;} int List::list () {return m_ilength;}    BOOL List::getelem (int i,int *e) {if (I < 0 | | I >=m_isize) return false;    *e = M_plist[i]; return true;}    int List::locateelem (int *e) {for (int i = 0;i < M_ilength;++i) {if (*e = = M_plist[i]) return i; } return-1;}    BOOL List::P riorelem (int *currentelem,int *preelem) {int temp = Locateelem (*currentelem);    if (temp = =-1) return false;        else{if (temp = = 0) return false;            else *preelem = m_plist[temp-1];    return true;    }}bool list::nextelem (int *currentelem,int *nextelem) {int temp = Locateelem (*currentelem); if (temp = =-1)       return false;        else{if (temp = = m_ilength-1) return false;        else *preelem = m_plist[temp + 1];    return true;    }}void Lisit::listtraverse () {for (int i = 0;i < M_ilength;++i) {cout<<m_plist[i];    }}bool list::listdelete (int i,int *e) {if (I < 0 | | I >= m_ilength) return false;    *e = M_plist[i]; for (k = i + 1;k < m_ilength;;    ++K) {M_plist[k-1] = m_plist[k];    } m_ilength--; return true;}

  

(c + +) data structure sequence table coding exercise

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.