


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
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é)點(diǎn)插入到鏈表后 */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; /* 從開始字符進(jìn)行比較 */ while (p->next != NULL) && (q->next != NULL) /* 進(jìn)行匹配檢驗(yàn) */ &
15、#160; if (p->ch = q->ch) p = p->next; q = q->next;
16、160; else sNext = sNext->next; &
17、#160; p = sNext; /* 指向主串中的下一個(gè) */ 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)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 六一社區(qū)創(chuàng)新活動方案
- 六一聯(lián)歡活動方案
- 六一閱讀節(jié)活動方案
- 六好工會創(chuàng)建活動方案
- 醫(yī)療保障考試試題及答案
- 云客服安全試題及答案
- 泌尿試題及答案
- 一級考試試題及答案
- 云南公務(wù)員試題及答案
- 安全培訓(xùn)一級試題及答案
- 2025至2030軍工裝備行業(yè)市場發(fā)展現(xiàn)狀及競爭形勢及有效策略與實(shí)施路徑評估報(bào)告
- 兵團(tuán)精神試題及答案
- 村寨垃圾收費(fèi)管理制度
- 江蘇保安證考試題及答案
- 2024年江西省中考生物·地理合卷試卷真題(含答案逐題解析)
- 抑郁病診斷證明書
- 試驗(yàn)設(shè)計(jì)與數(shù)據(jù)處理作業(yè)333333
- 樹脂膠水物質(zhì)資料安全表(MSDS)
- 降低給藥錯(cuò)誤發(fā)生率.pptx
- 叉車自查表 廠內(nèi)機(jī)動車輛(叉車)安全自查表
- 工程造價(jià)畢業(yè)論文
評論
0/150
提交評論