Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int getLastNumber(int number) {
- int lastNumber = number % 10;
- return lastNumber;
- }
- void swap(int *first, int *second) {
- int temp = *first;
- *first = *second;
- *second = temp;
- }
- class SuperArray {
- private:
- int MAX_SIZE;
- int size;
- int * array;
- void sort();
- void push(int number);
- void show();
- void menu();
- public:
- SuperArray(int maxSize);
- };
- void SuperArray::sort() {
- int i, j;
- for (i = 0; i < size - 1; i++)
- for (j = 0; j < size - i - 1; j++)
- if (getLastNumber(array[j]) > getLastNumber(array[j + 1]))
- swap(array[j], array[j + 1]);
- }
- void SuperArray::push(int number) {
- if (size < MAX_SIZE) {
- array[size] = number;
- sort();
- size++;
- }
- else
- cout << "YOU overfilled the array!!!!!!" << endl;
- }
- void SuperArray::show() {
- cout << endl;
- for (int i = 0; i < size; i++)
- cout << array[i] << ' ';
- cout << endl;
- }
- void SuperArray::menu() {
- cout << "1. Display array" << endl;
- cout << "2. Push in array" << endl;
- while (1) {
- int variant;
- cin >> variant;
- switch (variant) {
- case 1:
- show();
- break;
- case 2:
- cout << "Enter the number: ";
- int number;
- cin >> number;
- push(number);
- break;
- default:
- cout << "Wrong" << endl;
- }
- }
- }
- SuperArray::SuperArray(int maxSize) {
- MAX_SIZE = maxSize;
- array = new int[MAX_SIZE];
- menu();
- }
- void main() {
- cout << "Enter the max size of array: ";
- int maxSize;
- cin >> maxSize;
- SuperArray arr(maxSize);
- system("pause");
- }
Add Comment
Please, Sign In to add comment