voidInsertList(PTNode s, PTNode t, char id) { //serach the id in the list s PTNode temp = NULL; int isfoundinblock = 0; while (s->next != NULL) { //loop over block for (int i = 0; i < SIZE; i++) { //is found id in block if (s->character[i] == id) { isfoundinblock = 1; } //not found id in block else { continue; } } if (isfoundinblock == 1) { break; } //search next block s = s->next; } }
查询到id的后续操作
首先将同个block中id后的字符复制到buffer中,然后把该位置的字符定义为1(pass)
1 2 3 4 5 6
isfoundinblock = 1; //copy remain of block to buffer for (int j = i + 1; j < SIZE; j++) { buffer->character[j - i - 1] = s->character[j]; s->character[j] = 1; }
将s串指向t串,s串后半部分位置储存到temp
1 2 3
//relocation of pointers temp = s->next; s->next = t->next;
将t串最后一个block后缀改为1(pass)
1 2 3 4 5 6 7 8 9 10
//t tail of block set 1 while (t->next != NULL) { t = t->next; } for (int j = 0; j < SIZE; j++) { if (t->character[j] != '\0') { continue; } t->character[j] = 1; }
将t串末尾指向buffer,将buffer指向temp
1 2 3
//relocation of pointers t->next = buffer; buffer->next = temp;
图示
特别的,当id为某个block末位字符时,代码相同,图示如下:
未查询到id的后续操作
将s串最后一个block后缀改为1(pass),并将s串指向t串
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
while (s->next != NULL) { ... } if (isfoundinblock == 0) { //s tail of block set 1 while (s->next != NULL) { s = s->next; } for (int j = 0; j < SIZE; j++) { if (s->character[j] != '\0') { continue; } s->character[j] = 1; } //relocation of pointers s->next = t->next; }
>>>input abcdefg 111 c <<<output id: c s : abcdefg t : 111 op: abc111defg --- >>>input abcdefg 111 e <<<output id: e s : abcdefg t : 111 op: abcde111fg --- >>>input abcdefg 111 z <<<output id: z s : abcdefg t : 111 op: abcdefg111 --- >>>input abcdefghij 111222 i <<<output id: i s : abcdefghij t : 111222 op: abcdefghi111222j --- >>>input abcde 11111 a <<<output id: a s : abcde t : 11111 op: a11111bcde ---
voidWriteInList(PTNode pHead) { int flag = 1; while (flag) { PTNode pLast = pHead; while (pLast->next != NULL) { pLast = pLast->next; } flag = WriteInBlock(pLast); } }
voidPrintList(PTNode pHead) { PTNode p = pHead->next; while (p != NULL) { for (int i = 0; i < SIZE; i++) { if (p->character[i] == '\0') { printf("\n"); break; } elseif (p->character[i] == 1) { continue; } else { printf("%c", p->character[i]); } } p = p->next; } }
voidInsertList(PTNode s, PTNode t, char id) { //serach the id in the list s PTNode temp = NULL; int isfoundinblock = 0; while (s->next != NULL) {
//loop over block for (int i = 0; i < SIZE; i++) { //is found id in block if (s->character[i] == id) { isfoundinblock = 1; //copy remain of block to buffer for (int j = i + 1; j < SIZE; j++) { buffer->character[j - i - 1] = s->character[j]; s->character[j] = 1; } //relocation of pointers temp = s->next; s->next = t->next; //t tail of block set 1 while (t->next != NULL) { t = t->next; } for (int j = 0; j < SIZE; j++) { if (t->character[j] != '\0') { continue; } t->character[j] = 1; }
//relocation of pointers t->next = buffer; buffer->next = temp; } //not found id in block else { continue; } } if (isfoundinblock == 1) { break; } //search next block s = s->next; } if (isfoundinblock == 0) { //s tail of block set 1 while (s->next != NULL) { s = s->next; } for (int j = 0; j < SIZE; j++) { if (s->character[j] != '\0') { continue; } s->character[j] = 1; } //relocation of pointers s->next = t->next; } }