Files
Data-Structure/LinearList/as-List/main.cpp
2025-07-20 11:22:32 +08:00

50 lines
1.3 KiB
C++

#include <iostream>
#include <string>
#include "linearList.h"
#include "chainNode.h"
#include "chain.h"
/*
NEEDED TEST:
ok int capacity();
ok bool empty() const;//If empty, return 0;
ok int size() const; //Return Array Size
ok virtual T& get(int theIndex) const override; // Return Arr[theIndex]
ok virtual int indexOf(const T & theElement) const override; //Return the index of "theElement" first appeared
ok virtual void erase(int theIndex) override; //Erase Arr[theIndex]
ok virtual T* changeLength(T * x, int oldlength, int newlength) override;
ok virtual void insert(int theIndex, const T & theElement) override; //Insert theElement to place Arr[theIndex]
ok virtual void output(std::ostream & out) const override; //cout
*/
int main() {
chain<int> test(10);
std::cout << "Is Empty: " << test.empty() << std::endl;
for (int i = 0; i <= 10; i++) {
test.insert(i, i + 1);
}
test.output();
std::cout << test.get(4) << std::endl; //output 5
test.insert(10, 11); // 1 2 3 4 5 6 7 8 9 10 11
test.output();
std::cout << test.size() << std::endl;
test.erase(0); // 2 3 4 5 6 7 8 9 10 11
test.output();
test.insert(5, 3);
test.output();
std::cout << test.indexOf(3) << std::endl;
return 0;
}
/*
Result:
Is Empty: 1
1 2 3 4 5 6 7 8 9 10
5
1 2 3 4 5 6 7 8 9 10 11
11
2 3 4 5 6 7 8 9 10 11
2 3 4 5 6 3 7 8 9 10 11
1
*/