add arraylist + demo
This commit is contained in:
87
c_os/user/demo/ArrayListDemo.cc
Normal file
87
c_os/user/demo/ArrayListDemo.cc
Normal file
@ -0,0 +1,87 @@
|
||||
#include "user/demo/ArrayListDemo.h"
|
||||
|
||||
void ArrayListDemo::run() {
|
||||
kout << "Initial list size: " << dec << this->list.size() << endl;
|
||||
|
||||
kout << "Adding elements in order" << endl;
|
||||
for (unsigned int i = 0; i < 5; ++i) {
|
||||
this->list.insert(i);
|
||||
}
|
||||
this->list.print();
|
||||
|
||||
kout << "Removing all elements from the front" << endl;
|
||||
for (unsigned int i = 0; i < 5; ++i) {
|
||||
this->list.remove_first();
|
||||
}
|
||||
this->list.print();
|
||||
|
||||
// ============================================================
|
||||
|
||||
kout << "Adding elements in order with realloc" << endl;
|
||||
for (unsigned int i = 0; i < 10; ++i) {
|
||||
kout << "Add " << dec << i << endl;
|
||||
this->list.insert(i);
|
||||
}
|
||||
this->list.print();
|
||||
|
||||
kout << "Removing all elements from the back" << endl;
|
||||
for (unsigned int i = 0; i < 10; ++i) {
|
||||
this->list.remove_last();
|
||||
}
|
||||
this->list.print();
|
||||
|
||||
// ============================================================
|
||||
|
||||
for (unsigned int i = 0; i < 5; ++i) {
|
||||
this->list.insert(i);
|
||||
}
|
||||
this->list.print();
|
||||
|
||||
kout << "Adding inside the list (at idx 0, 2, 5)" << endl;
|
||||
this->list.insert_at(10, 0);
|
||||
this->list.insert_at(10, 2);
|
||||
this->list.insert_at(10, 5);
|
||||
this->list.print();
|
||||
|
||||
kout << "Removing inside the list (at idx 0, 2, 5)" << endl;
|
||||
this->list.remove_at(0);
|
||||
this->list.remove_at(2);
|
||||
this->list.remove_at(5);
|
||||
this->list.print();
|
||||
|
||||
for (unsigned int i = 0; i < 5; ++i) {
|
||||
this->list.remove_first();
|
||||
}
|
||||
this->list.print();
|
||||
|
||||
// ============================================================
|
||||
|
||||
kout << "Mirror scheduling behavior" << endl;
|
||||
|
||||
// These are the threads
|
||||
int active = 0; // Idle thread
|
||||
this->list.insert(1);
|
||||
this->list.insert(2);
|
||||
this->list.insert(3);
|
||||
this->list.print();
|
||||
|
||||
kout << "Starting..." << endl;
|
||||
for (unsigned int n = 0; n < 10000000; ++n) {
|
||||
this->list.insert(active);
|
||||
active = list.remove_first();
|
||||
|
||||
if (this->list.size() != 3) {
|
||||
kout << "ERROR: Thread went missing" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
if (n < 5) {
|
||||
this->list.print();
|
||||
}
|
||||
}
|
||||
kout << "Finished." << endl;
|
||||
|
||||
this->list.print();
|
||||
|
||||
scheduler.exit();
|
||||
}
|
||||
Reference in New Issue
Block a user