


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、/* * 串的簡單模式匹配 * */ #include <stdio.h>#incl
2、ude <stdlib.h>/* 定義單鏈表結(jié)構(gòu)體 */struct node char ch; struct node *next;/* 初始化單鏈表 */void init(struct node *h) *h = (struct node*)malloc(sizeof(struct
3、node); (*h)->next = NULL; return;/* 將x結(jié)點插入到鏈表后 */void append(struct node *p, int x) struct node *s; s = (struct node*)malloc(sizeof(str
4、uct node); s->ch = x; s->next = NULL; /* 移動到表尾 */ while (p->next != NULL) p
5、60;= p->next; p->next = s; return;void display(struct node *p) printf("You typed string is: "
6、); while (p->next != NULL) printf("%c", p->next->ch); p = p->next;
7、; printf(" "); return;int main(int argc, char *argv) struct node *t, *s; /* s為主串, t為模式串 */ struct node *sNext, *p, *q;
8、; int i, x = 0; init(&s); printf("Please type main string: "); while (x != ' ')
9、60; x = getchar(); if (x != ' ') append(s, x);
10、60; /* 添加到表尾 */ display(s); init(&t); printf("Please type substring: &qu
11、ot;); x = 0; while (x != ' ') x = getchar(); if (x != ' ')
12、 append(t, x); /* 添加到表尾 */ display(t
13、); /* 初始化 */ sNext = s->next; p = sNext; q = t->next; i = 1;
14、60; /* 從開始字符進行比較 */ while (p->next != NULL) && (q->next != NULL) /* 進行匹配檢驗 */ &
15、#160; if (p->ch = q->ch) p = p->next; q = q->next;
16、160; else sNext = sNext->next; &
17、#160; p = sNext; /* 指向主串中的下一個 */ q = t->next; /* 指針后退重新開始匹配 */ &
18、#160; i+; /* 記錄位置 */ /* 輸出結(jié)果 */ if (q->next) = NULL && (t->next->ch = s->next->ch) printf("match position: %d", i
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度離職員工保密協(xié)議及競業(yè)限制合同簽訂流程規(guī)范
- 二零二五年度知識產(chǎn)權(quán)保護合伙人合作協(xié)議范本
- 法律實務案例分析題及法律理論應用題卷
- 共享平臺合作協(xié)議知識產(chǎn)權(quán)合作開發(fā)協(xié)議
- 高峰會議交流與合作備忘錄
- 油漆勞務合同油漆工用工合同
- 基于大數(shù)據(jù)的農(nóng)業(yè)現(xiàn)代化種植管理系統(tǒng)開發(fā)實踐
- 企業(yè)形象策劃及活動推廣合作協(xié)議
- 精紡織品采購合同
- 高一英語動詞時態(tài)對照分析教案
- 2025屆高考化學二輪復習:晶胞的相關性質(zhì)及計算(含解析)
- 2024年沙洲職業(yè)工學院高職單招職業(yè)適應性測試歷年參考題庫含答案解析
- 2024年山東鋁業(yè)職業(yè)學院高職單招數(shù)學歷年參考題庫含答案解析
- 2024年山東勞動職業(yè)技術(shù)學院高職單招語文歷年參考題庫含答案解析
- 融合智慧數(shù)據(jù)的圖書館數(shù)智服務平臺研究
- 員工外宿免責協(xié)議書(2篇)
- IT科技產(chǎn)業(yè)云計算服務平臺開發(fā)方案
- 2025年中國航天科工招聘筆試參考題庫含答案解析
- 血透室停電停水應急預案
- 4《公民的基本權(quán)利和義務》(第2課時)教學實錄-2024-2025學年道德與法治六年級上冊統(tǒng)編版
- 人教版小學數(shù)學三年級下冊第一單元《位置與方向(一)》單元測試
評論
0/150
提交評論