diff --git a/CLion/CourseBook/0403_LString/LString.c b/CLion/CourseBook/0403_LString/LString.c index 0351aee..91aa9bc 100644 --- a/CLion/CourseBook/0403_LString/LString.c +++ b/CLion/CourseBook/0403_LString/LString.c @@ -359,6 +359,7 @@ Status StrInsert(LString* S, int pos, LString T) { // 移动目标块中pos位置之前的元素 for(i = 1; i <= (pos - 1) % CHUNKSIZE; i++) { h->ch[j++] = p->ch[i - 1]; + p->ch[i - 1] = '\0'; } } diff --git a/Dev-C++/CourseBook/0403_LString/LString.cpp b/Dev-C++/CourseBook/0403_LString/LString.cpp index ab9c5dd..a8f895a 100644 --- a/Dev-C++/CourseBook/0403_LString/LString.cpp +++ b/Dev-C++/CourseBook/0403_LString/LString.cpp @@ -292,19 +292,19 @@ Status StrInsert(LString* S, int pos, LString T) { Chunk* r; Chunk* s; int i, j, count; - + if(pos < 1 || pos > (*S).curlen + 1) { return ERROR; } - + // ĴΪգǰ if(StrEmpty(T)) { return OK; } - + // ¼ʼֹ h = t = NULL; - + // TеĿ飨ֻƽṹ for(r = T.head; r != NULL; r = r->next) { s = (Chunk*) malloc(sizeof(Chunk)); @@ -312,7 +312,7 @@ Status StrInsert(LString* S, int pos, LString T) { exit(OVERFLOW); } s->next = NULL; - + if(r == T.head) { h = t = s; } else { @@ -320,7 +320,7 @@ Status StrInsert(LString* S, int pos, LString T) { t = s; } } - + // SеposԪڵĿ飨עΪĿ飩ָpreָǰ if(pos >= 1 && pos <= CHUNKSIZE) { pre = NULL; // ˵posԪڿΪhead @@ -331,11 +331,11 @@ Status StrInsert(LString* S, int pos, LString T) { } p = pre->next; } - + /* * htΧĿ뵽posڵĿ֮ǰ */ - + if(pre == NULL) { t->next = (*S).head; (*S).head = h; @@ -343,69 +343,70 @@ Status StrInsert(LString* S, int pos, LString T) { pre->next = h; t->next = p; } - + if(pre == (*S).tail) { (*S).tail = t; } - + /* * ƶ/Ԫ */ - + j = 0; - + // 뵽ijġм䡱 if((pos - 1) % CHUNKSIZE != 0) { // ƶĿposλ֮ǰԪ for(i = 1; i <= (pos - 1) % CHUNKSIZE; i++) { h->ch[j++] = p->ch[i - 1]; + p->ch[i - 1] = '\0'; } } - + r = T.head; i = 0; - + // TеԪصS for(count = 1; count <= T.curlen; count++) { h->ch[j] = r->ch[i]; - + j = (j + 1) % CHUNKSIZE; i = (i + 1) % CHUNKSIZE; - + if(j == 0) { h = h->next; } - + if(i == 0) { r = r->next; } } - + // Tһа'\0' if(T.curlen % CHUNKSIZE != 0) { r = p; // ָĿ i = (pos - 1) % CHUNKSIZE; - + // ƶĿposλü֮Ԫ for(count = pos; count <= (*S).curlen; count++) { h->ch[j] = r->ch[i]; r->ch[i] = '\0'; - + j = (j + 1) % CHUNKSIZE; i = (i + 1) % CHUNKSIZE; - + if(j == 0) { h = h->next; } - + if(i == 0) { r = r->next; } } } - + (*S).curlen += T.curlen; - + return OK; } diff --git a/VisualC++/CourseBook/0403_LString/LString.c b/VisualC++/CourseBook/0403_LString/LString.c index ab9c5dd..8c3a412 100644 --- a/VisualC++/CourseBook/0403_LString/LString.c +++ b/VisualC++/CourseBook/0403_LString/LString.c @@ -359,6 +359,7 @@ Status StrInsert(LString* S, int pos, LString T) { // ƶĿposλ֮ǰԪ for(i = 1; i <= (pos - 1) % CHUNKSIZE; i++) { h->ch[j++] = p->ch[i - 1]; + p->ch[i - 1] = '\0'; } } diff --git a/VisualC++/CourseBook/CourseBook.sdf b/VisualC++/CourseBook/CourseBook.sdf index 1cc8ec8..d8a2bcd 100644 Binary files a/VisualC++/CourseBook/CourseBook.sdf and b/VisualC++/CourseBook/CourseBook.sdf differ diff --git a/VisualC++/CourseBook/CourseBook.suo b/VisualC++/CourseBook/CourseBook.suo index fc65e73..c2b2244 100644 Binary files a/VisualC++/CourseBook/CourseBook.suo and b/VisualC++/CourseBook/CourseBook.suo differ