第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

手寫模板類 - 底層數(shù)組,有序。理論沒錯(cuò),簡(jiǎn)單測(cè)試過了,大家覺得有問題可以提一下

#pragma once

#include <iostream>


using namespace std;


template <typename T>

class MyList {

public :

MyList(int _size = 32); // 構(gòu)造一個(gè)線性表,默認(rèn)32位 ? ?數(shù)組底層,有序

~MyList();// 銷毀線性表

void clearList(); // 清空線性表

bool listEmpty(); // 判空

int listLength(); // 線性表實(shí)際大小

int locateElem(T &elem); // 返回第一個(gè)滿足elem的數(shù)組的元素位置

void travelList(); // 遍歷數(shù)組


bool isIndexArr(int index); //判斷index是否越界

void expend(); // 擴(kuò)容


bool getElemPrior(T &current, int index ,T &proir); // 獲取指定下標(biāo)的前驅(qū)(上一個(gè)位置的值)

bool getElem(T &elem,int index); // 獲取指定下標(biāo)的值,返回獲取的值

bool getElemNext(T &current, int index, T &next); // 獲取指定下標(biāo)的后繼(下一個(gè)位置的值)


bool insertElem(T &elem, int index); // 向指定位置插入元素,如果線性表滿,則擴(kuò)從 N*2+1

bool deleteElem(T &elem, int index); // 刪除指定位置元素,并返回一個(gè)被刪除的值


private :

T *myList; // 線性表

int size; //線性表容量

int length; //線性表實(shí)際大小

};



template <typename T>

MyList<T>::MyList(int _size) {

size = _size;

myList = new T[_size];

clearList();

} // 構(gòu)造一個(gè)線性表,默認(rèn)32位 ? ?數(shù)組底層,有序


template <typename T>

MyList<T>::~MyList(){ ?

delete []myList;

myList = NULL;

}// 銷毀線性表


template <typename T>

void MyList<T>::clearList(){ ??

length = 0;

} // 清空線性表


template <typename T>

bool MyList<T>::listEmpty(){ ?

return 0 == length ? true : false;

} // 判空


template <typename T>

int MyList<T>::listLength(){ ?

return length;

} // 線性表實(shí)際大小


template <typename T>

int MyList<T>::locateElem(T &elem){ ?

for (int i = 0; i < length; i++) {

if (myList[i] == elem)

return i;

}

return -1;

} // 返回第一個(gè)滿足elem的數(shù)組的元素位置?


template <typename T>

void MyList<T>::travelList() {

if (listEmpty())

return;

for (int i = 0; i < length; i++)

cout << myList[i];

} // 遍歷數(shù)組




template <typename T>

bool MyList<T>::isIndexArr(int index) {

return index >= length||index <0 ? true : false;

} //判斷index是否越界


template <typename T>

void MyList<T>::expend() {

if (length < size)

return;

T *cacheList = myList;

myList = new T[size << 1 + 1];

for (int i = 0; i < length; i++)

myList[i] = cacheList[i];

delete[]cacheList;

cacheList = NULL;

} // 擴(kuò)容



template <typename T>

bool MyList<T>::getElemPrior(T &current, int index, T &proir){ ??

if (isIndexArr(index))

return false;

current = myList[index];

0 == index ? proir = NULL : proir = myList[index - 1];

return true;

} // 獲取指定下標(biāo)的前驅(qū)(上一個(gè)位置的值)


template <typename T>

bool MyList<T>::getElem(T &elem, int index){

if (isIndexArr(index))

return false;

elem = myList[index];

return true;

} // 獲取指定下標(biāo)的值,返回獲取的值


template <typename T>

bool MyList<T>::getElemNext(T &current, int index, T &next){

if (isIndexArr(index))

return false;

current = myList[index];

index == length - 1 ? next = NULL : next = myList[index + 1];

return true;

} // 獲取指定下標(biāo)的后繼(下一個(gè)位置的值)




template <typename T>

bool MyList<T>::insertElem(T &elem, int index){

if (index > length)

return false;

expend();

for (int i = size - 1; i > index; i--)

myList[i] = myList[i - 1];

myList[index] = elem;

length++;

return true;

} // 向指定位置插入元素, - 如果線性表滿,則擴(kuò)從 N*2+1


template <typename T>

bool MyList<T>::deleteElem(T &elem, int index){

if (isIndexArr(index))

return false;

elem = myList[index];

for (int i = index; i < length - 1; i++)?

myList[i] = myList[i+1];

length--;

return true;

} // 刪除指定位置元素,并返回一個(gè)被刪除的值


正在回答

1 回答

newbee

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

手寫模板類 - 底層數(shù)組,有序。理論沒錯(cuò),簡(jiǎn)單測(cè)試過了,大家覺得有問題可以提一下

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)