Answer to Question #245855 in C++ for Buda

Question #245855

An array list is one of the most important data structures used in many applications


1
Expert's answer
2021-10-02T15:45:29-0400
#include <iostream>
using namespace std;
//Functions of ArrayLists:

class ArrayList {
public:
    ~ArrayList();

private:
//  Some declarations for implementations of the above functions:
    int data;
    int item_andex;

public:
    ArrayList doubleCapacity(int *x, int y);
    ArrayList halfCapacity(int *x, int y);

private:
    ArrayList arr_List;


//    Implementations of the functions of ArrayList

public:
    ArrayList() {
        data = 0;
        item_andex = 0;
       *arr_List = new int[data];
    }


    // Insertion function of ArrayList
    void add(int item) {
        arr_List[item_andex] = item;
        data++;
        item_andex++;


        if (data == item_andex) {
            arr_List = doubleCapacity(arr_List, data);
        }
    }

//Deleting function of ArrayList
    int deleteLast() {
        int count = 0;
        if (arr_List != 0) {
            count = arr_List[size];
            arr_List[size] = NULL;
            if (item_andex < item_andex * 2) {
                arr_List = halfCapacity(arr_List, item_andex);
            }
        } else {
            cout << "Array is empty\n";
        }
        return count;
    }

//  ArrayList Size() function
    int size() {
        int count = 0;
        for (int x = 0; x < arr_List.length; x++) {
            if (arr_List[x] != NULL)
                count++;
        }
        return count;
    }
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS