freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

數(shù)據(jù)結(jié)構(gòu)2清華大學(xué)ppt(編輯修改稿)

2025-02-16 06:33 本頁(yè)面
 

【文章內(nèi)容簡(jiǎn)介】 。 i++) rowSize[smArray[i].col]++。 rowStart[0] = 0。 for (i = 1。 i Cols。 i++) rowStart[i] = rowStart[i1]+rowSize[i1]。 for (i = 0。 i Terms。 i++) { j = rowStart [smArray[i].col]。 [j].row = smArray[i].col。 [j].col = smArray[i].row。 [j].value = smArray[i].value。 rowStart [smArray[i].col]++。 } 44 } delete [ ] rowSize。 delete [ ] rowStart。 } 帶行指針數(shù)組的二元組表 ? 稀疏矩陣的三元組表可以用帶行指針數(shù)組的二元組表代替。 ? 在行指針數(shù)組中元素個(gè)數(shù)與矩陣行數(shù)相等。第 i 個(gè)元素的下標(biāo) i 代表矩陣的第 i 行,元素的內(nèi)容即為稀疏矩陣第 i 行的第一個(gè)非零元素在二元組表中的存放位置 。 45 ? 二元組表中每個(gè)二元組只記錄非零元素的列號(hào)和元素值,且各二元組按行號(hào)遞增的順序排列。 ??????????????????????0020220000000000080000300040140000000130011012 行指針數(shù)組 row 0 0 1 3 2 4 3 6 4 7 5 7 二元組表 data col value 0 0 12 1 2 11 2 5 13 3 6 14 4 1 4 5 5 3 6 3 8 7 1 9 8 4 2 46 字符串 (String) ? 字符串是 n ( ? 0 ) 個(gè)字符的有限序列, 記作 S : “c1c2c3…c n” 其中, S 是串名字 “ c1c2c3…c n”是串值 ci 是串中字符 n 是串的長(zhǎng)度, n = 0 稱為 空串 。 ? 例如 , S = “Tsinghua University”。 ? 注意: 空串 和 空白串 不同,例如 “ ” 和 “” 分別表示長(zhǎng)度為 1的空白串和長(zhǎng)度為 0的空串。 47 ? 串中任意個(gè)連續(xù)字符組成的子序列稱為該串的 子串 ,包含子串的串相應(yīng)地稱為主 串 。 ? 通常將子串在主串中首次出現(xiàn)時(shí),該子串首字符對(duì)應(yīng)的主串中的序號(hào),定義為子串在主串中的位置。例如,設(shè) A和 B分別為 A = “This is a string” B = “is” 則 B 是 A 的子串, A 為主串。 B 在 A 中出現(xiàn)了兩次,首次出現(xiàn)所對(duì)應(yīng)的主串位置是 2(從0開始)。因此,稱 B 在 A 中的位置為 2。 ? 特別地,空串是任意串的子串,任意串是其自身的子串。 48 ? 通常在程序中使用的串可分為兩種:串變量和串常量。 ? 串常量在程序中只能被引用但不能改變它的值,即只能讀不能寫。通常串常量是由直接量來表示的,例如語(yǔ)句 Error (“overflow”) 中 “ overflow”是直接量。但有的語(yǔ)言允許對(duì)串常量命名,以使程序易讀、易寫。如 C++中,可定義 const char path[] = “dir/bin/appl”。 ? 這里 path是一個(gè)串常量。串變量和其它類型的變量一樣,其取值可以改變。 49 字符串的類定義 ifndef ASTRING_H //定義在文件“ ”中 define ASTRING_H define defaultSize = 128。 //字符串的最大長(zhǎng)度 class AString { //對(duì)象 : 零個(gè)或多個(gè)字符的一個(gè)有限序列。 private: char *ch。 //串存放數(shù)組 int curLength。 //串的實(shí)際長(zhǎng)度 int maxSize。 //存放數(shù)組的最大長(zhǎng)度 public: 50 AString(int sz = defaultSize)。 //構(gòu)造函數(shù) AString(const char *init )。 //構(gòu)造函數(shù) AString(const AStringamp。 ob)。 //復(fù)制構(gòu)造函數(shù) ~ AString() {delete [ ]ch。 } //析構(gòu)函數(shù) int Length() const { return curLength。 } //求長(zhǎng)度 Astringamp。 operator() (int pos, int len)。 //求子串 bool operator == (AStringamp。 ob) const { return strcmp (ch, ) == 0。 } //判串相等 . 若串相等 , 則函數(shù)返回 true bool operator != (AStringamp。 ob) const { return strcmp (ch, ) != 0。 } //判串不等 . 若串不相等 , 則函數(shù)返回 true 51 bool operator ! () const { return curLength == 0。 } //判串空否。若串空 , 則函數(shù)返回 true AStringamp。 operator = (AStringamp。 ob)。 //串賦值 AStringamp。 operator += (AStringamp。 ob)。 //串連接 charamp。 operator [ ] (int i)。 //取第 i 個(gè)字符 int Find (AStringamp。 pat, int k) const。 //串匹配 }。 52 字符串的構(gòu)造函數(shù) AString::AString(int sz) { //構(gòu)造函數(shù):創(chuàng)建一個(gè)空串 maxSize = sz。 ch = new char[maxSize+1]。 //創(chuàng)建串?dāng)?shù)組 if (ch == NULL) { cerr “存儲(chǔ)分配錯(cuò) !\n”。 exit(1)。 } curLength = 0。 ch[0] = ?\0?。 }。 53 字符串的構(gòu)造函數(shù) AString::AString(const char *init) { //復(fù)制構(gòu)造函數(shù) : 從已有字符數(shù)組 *init復(fù)制 int len = strlen(init)。 maxSize = (len defaultSize) ? len : defaultSize。 ch = new char[maxSize+1]。 //創(chuàng)建串?dāng)?shù)組 if (ch == NULL) { cerr “存儲(chǔ)分配錯(cuò) ! \n”。 exit(1)。 } curLength = len。 //復(fù)制串長(zhǎng)度 strcpy(ch, init)。 //復(fù)制串值 }; 54 字符串的復(fù)制構(gòu)造函數(shù) AString :: AString(const AStringamp。 ob) { //復(fù)制構(gòu)造函數(shù):從已有串 ob復(fù)制 maxSize = 。 //復(fù)制串最大長(zhǎng)度 ch = new char[curLength+1]。 //創(chuàng)建串?dāng)?shù)組 if (ch == NULL) { cerr “存儲(chǔ)分配錯(cuò) ! \n”。 exit(1)。 } curLength = 。 //復(fù)制串長(zhǎng)度 strcpy(ch, )。 //復(fù)制串值 }。 55 字符串重載操作的使用示例 序 號(hào) 重載操作 操作 使用示例 (設(shè)使用操作的當(dāng)前串為 S:‘ tsinghua?) 1 ( ) (int pos, int len) 取子串 S1 = S(3, 2), //S1結(jié)果為 ‘ ng? 2 == (const AStringamp。 ob) 判兩串 相等 S == S1 , //若 S與 S1相等 , 結(jié)果為 true,否則為 false 3 != (const AStringamp。 ob) 判兩串 不等 S != S1 , //若 S與 S1不等, 結(jié)果為 true,否則為 false 4 ! () 判串空 否 !S , //若串 S為空,結(jié)果為 true,否則為 false 56 序 號(hào) 重載操作 操作 使用示例 (設(shè)使用操作的當(dāng)前串為 S:‘ tsinghua?) 5 = (const AStringamp。 ob) 串賦值 S1 = S, //S1結(jié)果為‘ tsinghua? 6 += (const AStringamp。 ob) 串連接 若設(shè) S1為‘ university?, 執(zhí)行 S += S1, //S結(jié)果為‘ tsinghua university? 7 [ ] (int i) 取第 i 個(gè)字符 S[5], //取出字符為‘ h? 57 提取子串的算法示例 pos+len1 pos+len 1 ? curLen1 ? curLen 可以全部提取 只能從 pos取到串尾 i n f i n i t y i n f i n i t y pos = 2, len = 3 pos = 5, len = 4 f i n i t y 超出 58 串重載操作: 提取子串 AString AString::operator () (int pos, int len) { //從串中第 pos 個(gè)位置起連續(xù)提取 len 個(gè)字符形成 //子串返回 AString temp。 //建立空串對(duì)象 if (pos = 0 amp。amp。 pos+len1 maxLen amp。amp。 len 0) { //提取子串 if (pos+len1 = curLength) len = curLength pos。 //調(diào)整提取字符數(shù) = len。 //子串長(zhǎng)度 59 for (int i = 0, j = pos。 i len。 i++, j++) [i] = ch[j]。 //傳送串?dāng)?shù)組 [len] = ?\0?。 //子串結(jié)束 } return temp。 }。 ? 例:串 st = “university”, pos = 3, len = 4 使用示例 subSt = st(3, 4) 提取子串 subSt = “vers” 60 串重載操作 : 串賦值 AStringamp。 AString::operator = (const AStringamp。 ob) { if (amp。ob != this) { //若兩個(gè)串相等為自我賦值 delete []ch。 ch = new char[maxSize+1]。 //重新分配 if (ch
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖片鄂ICP備17016276號(hào)-1