-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
34 changed files
with
3,169 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#if !defined(_ARRAYLIST_H) | ||
#define _ARRAYLIST_H | ||
|
||
// * #define DEFAULT_MAX_SIZE 5 | ||
|
||
class ArrayList | ||
{ | ||
private: // * data | ||
int *L; // ! List element | ||
int maxSize; // * maximum element | ||
int curSize; // * current number element | ||
|
||
public: // * method | ||
ArrayList(int maxSize); // ! contructor *important (1)* | ||
~ArrayList(); // ! destructor | ||
// * basic method | ||
int size(); | ||
int indexOf(int e); | ||
int get(int i); | ||
void set(int i, int e); | ||
int remove(int i); | ||
void add(int i,int e); | ||
|
||
void clear(); | ||
int max(); | ||
int min(); | ||
|
||
int oddCount(); | ||
int evenCount(); | ||
float sum(); | ||
float mean(); | ||
void sort(); | ||
|
||
void swap(int &a, int &b); | ||
|
||
void appendRandom(int round); | ||
|
||
// * addition method | ||
void display(); | ||
|
||
}; | ||
|
||
#endif // _ARRAYLIST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/*************************************************************************************** | ||
* ID: 65037743 | ||
* NAME: Mr.Kidsadakorn Nuallaoong | ||
* DESCRIPTION: ArrayList Testing | ||
***************************************************************************************/ | ||
#include <iostream> | ||
#include "arrayList.h" | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
ArrayList list(5); | ||
|
||
int choice,index,element; | ||
|
||
do | ||
{ | ||
cout << "----------------- MENU -----------------" << endl << endl; | ||
|
||
cout << "================ DISPLAY ===============" << endl << endl; | ||
|
||
list.display(); | ||
|
||
cout << endl << "========================================" << endl << endl; | ||
|
||
cout << "1: Add element to List, add()" << endl; | ||
cout << "2: Remove element from list, remove()" << endl; | ||
cout << "3: Set element to list, set()" << endl; | ||
cout << "4: Get element from list, get()" << endl; | ||
cout << "5: Index of element, indexOf()" << endl; | ||
cout << "6: List size, size()" << endl; | ||
cout << "7: Clear list, clear()" << endl; | ||
cout << "8: Find maximum number from list, max()" << endl; | ||
cout << "9: Find minimum number from list, min()" << endl; | ||
cout << "0: Exit!!!!" << endl; | ||
|
||
cout << endl; | ||
|
||
cout << "Enter your choice : " ; cin >> choice; | ||
|
||
switch (choice) | ||
{ | ||
case 1: // * add | ||
cout << "Enter index : "; cin >> index; | ||
cout << "Enter element : "; cin >> element; | ||
list.add(index, element); | ||
break; | ||
|
||
case 2: // * remove | ||
cout << "Enter index : "; cin >> index; | ||
list.remove(index); | ||
break; | ||
|
||
case 3: // * set | ||
cout << "Enter index : "; cin >> index; | ||
cout << "Enter element : "; cin >> element; | ||
list.set(index, element); | ||
break; | ||
|
||
case 4: // * get | ||
cout << "Enter index : "; cin >> index; | ||
cout << "[Massage] list[" << index << "] is " << list.get(index) << endl; | ||
break; | ||
|
||
case 5: // * index of | ||
cout << "Enter element : "; cin >> element; | ||
list.indexOf(element); | ||
break; | ||
|
||
case 6: // * list size | ||
cout << "[Massage] Current List Size is " << list.size() << endl; | ||
break; | ||
|
||
case 7: // * clear | ||
list.clear(); | ||
break; | ||
|
||
case 8: // * max | ||
list.max(); | ||
break; | ||
|
||
case 9: // * min | ||
list.min(); | ||
break; | ||
|
||
case 0: | ||
cout << "Bye...." << endl << endl; | ||
cout << "-------------- Call method --------------" << endl; | ||
break; | ||
|
||
default: // * Exit | ||
cout << "[Massage] Wrong choice,try again..." << endl; | ||
} | ||
|
||
}while(choice != 0); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
run: all | ||
@clear | ||
@echo Program is running... | ||
|
||
@./program | ||
@rm -f *.o program | ||
|
||
all: main.o arrayList.o | ||
@g++ main.o arraylist.o -o program -g | ||
|
||
main.o: main.cpp | ||
@g++ -c main.cpp -o main.o -g | ||
|
||
arraylist.o: arrayList.cpp | ||
@g++ -c arrayList.cpp -o arrayList.o -g | ||
|
||
clean: | ||
@rm -f *.o program | ||
@echo Cleaning success...... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "ArrayStack.h" | ||
|
||
ArrayStack::ArrayStack(int maxSize) : ArrayList(maxSize) | ||
{ | ||
// * set maxSize = maxSize | ||
this->maxSize = maxSize; | ||
} | ||
|
||
void ArrayStack::push(int e) | ||
{ | ||
// * add to element | ||
add(size(), e); | ||
} | ||
|
||
int ArrayStack::pop() | ||
{ | ||
// * remove element index Size - 1 | ||
return remove(size() - 1); | ||
} | ||
|
||
int ArrayStack::top() | ||
{ | ||
// * get element index Size - 1 | ||
return get(size() - 1); | ||
} | ||
|
||
bool ArrayStack::isEmpty() | ||
{ | ||
return size() == 0; | ||
} | ||
|
||
bool ArrayStack::isFull() | ||
{ | ||
return size() == DEFAULT_STACK_SIZE; | ||
} | ||
|
||
void ArrayStack::swapTopTwo() | ||
{ | ||
// * get and remove element | ||
// * We can use pop(); ---> 2 line | ||
int a = remove(size() - 1); | ||
int b = remove(size() - 1); | ||
|
||
// * add element to first index | ||
// * We can use push(element); ---> 2 line | ||
add(size(), a); | ||
add(size(), b); | ||
} | ||
|
||
void ArrayStack::moveMaxToTop() | ||
{ | ||
// * find max value | ||
int a = max(); | ||
// * get and remove max stack | ||
remove(indexOf(max())); | ||
// * add element a to last index | ||
push(a); | ||
} | ||
|
||
void ArrayStack::sortStack() | ||
{ | ||
// * get sorting | ||
sort(); | ||
} | ||
|
||
void ArrayStack::flip() | ||
{ | ||
int j = size() - 1; | ||
|
||
for (j; j > 0; --j) | ||
{ | ||
// * get and remove element index[0] | ||
// * add element to j-1/r | ||
add(j, remove(0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#if !defined(_ARRAYSTACK_H) | ||
#define _ARRAYSTACK_H | ||
|
||
#include "../ArrayList/arrayList.h" | ||
|
||
#define DEFAULT_STACK_SIZE 5 | ||
|
||
class ArrayStack : public ArrayList | ||
{ | ||
private: | ||
int maxSize; | ||
|
||
public: | ||
ArrayStack(int maxSize = DEFAULT_STACK_SIZE); | ||
// ~ArrayStack(); | ||
|
||
void push(int e); | ||
int pop(); | ||
int top(); | ||
|
||
bool isEmpty(); | ||
bool isFull(); | ||
|
||
void swapTopTwo(); | ||
void moveMaxToTop(); | ||
void sortStack(); | ||
void flip(); | ||
}; | ||
|
||
#endif // _ARRAYSTACK_H |
Oops, something went wrong.