1
0
mirror of https://github.com/Didnelpsun/CS408.git synced 2026-02-11 14:45:57 +08:00

更新链表

This commit is contained in:
Didnelpsun
2021-09-13 23:34:01 +08:00
parent 02e490f1af
commit 189f9250c3
2 changed files with 11 additions and 7 deletions

View File

@@ -419,7 +419,7 @@ element_type* LinkListWithHead::Delete(int index, int length) {
// 如果此时i小于index-1表示遍历完还没有到达对应的索引
if (i < index - 1) {
cout << "Delete:删除索引值" << index << "过大!" << endl;
return false;
return data;
}
// 此时i==index-1start到达求end
end = start;
@@ -427,7 +427,7 @@ element_type* LinkListWithHead::Delete(int index, int length) {
data[i] = end->GetData();
end = end->GetNext();
if (end == nullptr) {
cout << "Delete:删除索引最大值" << index + length - 1 << "大于链表最大索引" << length << endl;
cout << "Delete:删除索引最大值" << index + length - 1 << "大于链表最大索引" << length << "" << endl;
return data;
}
}
@@ -438,6 +438,8 @@ element_type* LinkListWithHead::Delete(int index, int length) {
start->SetNext(end->GetNext());
}
this->SetLength(this->GetLength() - length);
free(start);
free(end);
return data;
}
@@ -483,7 +485,7 @@ element_type* LinkListWithoutHead::Delete(int index, int length) {
}
end = end->GetNext();
if (end == nullptr) {
cout << "Delete:删除索引最大值" << index + length - 1 << "大于链表最大索引" << length << endl;
cout << "Delete:删除索引最大值" << index + length - 1 << "大于链表最大索引" << length << "" << endl;
return data;
}
}
@@ -498,5 +500,7 @@ element_type* LinkListWithoutHead::Delete(int index, int length) {
start->SetNext(end->GetNext());
}
this->SetLength(this->GetLength() - length);
free(start);
free(end);
return data;
}

View File

@@ -3,7 +3,7 @@
#include "../head/sequence_list.h"
#include "../head/link_list.h"
int SequenceListTest() {
bool SequenceListTest() {
DynamicSequenceList list;
element_type a[6] = {'1','2','3','4','5','6'};
list.LoopInsert(a, 0, 6);
@@ -14,10 +14,10 @@ int SequenceListTest() {
cout << b[i] << endl;
}
list.Destroy();
return 0;
return true;
}
int LinkListTest() {
bool LinkListTest() {
element_type a[6] = {'0', '1','2','3','4','5' };
// LinkListWithHead list;
// list.NextInsert(a, 0, 5);
@@ -38,5 +38,5 @@ int LinkListTest() {
cout << b[i] << endl;
}
list->Print();
return 0;
return true;
}