Please help me finish my code.
Before the final pause in the main function, create an ArrayList of another type such as double, char, short, bool, float, etc. Your choice. Add five data items to your array as we did for the int and string array lists. Print them out with a for loop as we did before. Print out the count and capacity of your new array list.
Source.cpp
#include
#include
#include
#include "ArrayList.h"
using namespace std;
/// Entry point to the application
int main(void)
{
// Check for memory leaks
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF |
_CRTDBG_LEAK_CHECK_DF);
#endif
// Create an int ArrayList
ArrayList intList;
intList.add(27);
intList.add(13);
intList.add(42);
intList.add(22);
intList.add(19);
for (int i = 0; i < intList.getCount();
i++)
{
cout << intList.get(i)
<< " , ";
}
cout << "\n" << endl;
cout << " Count: " << intList.getCount()
<< endl;
cout << " Capacity: " <<
intList.getCapacity() << endl;
cout << "\n\n" << endl;
// Create a string ArrayList
ArrayList strList;
strList.add("Jade");
strList.add("Caiden");
strList.add("Megan");
strList.add("Jonathan");
// Display list data
for (int i = 0; i < strList.getCount(); i++)
{
cout << strList.get(i)
<< " , ";
}
cout << "\n" << endl;
cout << " Count: " << strList.getCount()
<< endl;
cout << " Capacity: " <<
strList.getCapacity() << endl;
// Create a char ArrayList
ArrayList charList;
// Pause
cout << "\nPress any key to continue...";
cin.sync();
_getch();
system("pause");
return 0;
}
ArrayList.h
#pragma once
template
class ArrayList
{
private:
// Attributes
const static int DEFAULT_SIZE = 5;
// Constant for the initial
size
T* list;
// Pointer to the array
int count;
// Number of items in the list
int capacity;
// Current
size in memory
public:
// Constructors
ArrayList(void)
{
this->list = new
T[DEFAULT_SIZE];
this->capacity =
DEFAULT_SIZE;
this->count = 0;
}
ArrayList(int initialCapacity)
{
this->list = new
T[initialCapacity];
this->capacity =
initialCapacity;
this->count = 0;
}
// Destructor
~ArrayList(void)
{
// Delete the array pointer
if (this->list != nullptr)
{
delete[]
this->list;
this->list =
nullptr;
}
}
// Determine if the ArrayList if empty
bool isEmpty(void)
{
return count == 0;
// Array is empty if it has
zero items
}
/// Get the item at the given position
T get(int position)
{
if (position < count)
return
list[position];
else
return
NULL;
}
/// Add an item to the ArrayList
void add(T data)
{
// If the array is full, double the
size
if (count == capacity)
{
// Create bigger
array
capacity = 2 *
capacity;
T * temp = new
T[capacity];
// Copy items
from current array to bigger array
for (int i = 0;
i < count; i++)
{
temp[i] = list[i];
}
// Delete the
current array
delete[]
list;
// Rename the
bigger array to the current array name
list =
temp;
}
// Add the data item to the
array
list[count] = data;
// Increment the count
count++;
}
/// Remove item at the given position
void removeAt(int position)
{
// Replace every item from that
position on with the next item
for (int i = position; i < count
- 1; i++) // Notice "count - 1" to
copy last item to next to last position
{
list[i] = list[i
+ 1];
}
// Decrease the item count
count--;
}
/// Get the count of items in the ArrayList
int getCount(void)
{
return count;
}
/// Get the ArrayList current capacity
int getCapacity()
{
return capacity;
}
};
Please help me finish my code. Before the final pause in the main function, create an...
can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...
C++ Time the sequential search and the binary search methods several times each for randomly generated values, then record the results in a table. Do not time individual searches, but groups of them. For example, time 100 searches together or 1,000 searches together. Compare the running times of these two search methods that are obtained during the experiment. Regarding the efficiency of both search methods, what conclusion can be reached from this experiment? Both the table and your conclusions should...
PART 1 Modify the class ArrayList given in Exercise 1 by using expandable arrays. That is, if the list is full when an item is being added to this list, the elements will be moved to a larger array. The new array should have twice the size of the original array. Using the new class ArrayList, write a program to store 1,000 random numbers, each in the interval [0, 500]. The initial size of the array in the class should...
Fill the code in list.cpp app.cpp: #include "list.hpp" int main() { LinkedList aList; bool success = false; aList.evensFrontOddsEnd(3); aList.evensFrontOddsEnd(10); aList.evensFrontOddsEnd(6); aList.evensFrontOddsEnd(9); aList.evensFrontOddsEnd(17); aList.evensFrontOddsEnd(12); aList.printForward(); // output should be: 12 6 10 3 9 17 aList.printBackward(); // output should be: 17 9 3 10 6 12 success = aList.remove(17); if(success) cout << "17 Successfully Removed." << endl; success = aList.remove(10); if(success) cout << "10 Successfully Removed." << endl; success = aList.remove(7); // 7 is not in the list, so success should...
C++, Change the destroy_list function in the header file to a recursive destroy_list function, main is already set. Hint: It might be helpful to modify the function so that it uses a separate recursive function to perform whatever processing is needed. //////////////////////////////////////////////////////////////header.h////////////////////////////////////////////////////////////////////////////////////////////// #ifndef HEADER_H_ #define HEADER_H_ #include using namespace std; template <class T> class LL { private: struct LLnode { LLnode* fwdPtr; T theData; }; LLnode* head; public: LL(); void...
Hello, I have some errors in my C++ code when I try to debug it.
I tried to follow the requirements stated below:
Code:
// Linked.h
#ifndef INTLINKEDQUEUE
#define INTLINKEDQUEUE
#include <iostream>
usingnamespace std;
class IntLinkedQueue
{
private: struct Node {
int data;
Node *next;
};
Node *front; // -> first item
Node *rear; // -> last item
Node *p; // traversal position
Node *pp ; // previous position
int size; // number of elements in the queue
public:
IntLinkedQueue();...
C++ comment code Comment the following code #include <iostream> using namespace std; class Node { public: Node(int val); int value; Node* next; }; Node::Node(int val){ value = val; } class List { public: List(); // Uncomment the line below once you're ready List(List &other); void push_front(int value); bool pop_front(int &value); void push_back(int value); bool pop_back(int &value); int at(int index); void insert_at(int index, int value); void remove_at(int index); int size(); private: // other members you may have used Node* head; Node*...
I need help of how to include the merge sort code into this counter code found below: #include<iostream> using namespace std; int bubble_counter=0,selection_counter=0; // variables global void bubble_sort(int [], int); void show_array(int [],int); void selectionsort(int [], int ); int main() { int a[7]={4,1,7,2,9,0,3}; show_array(a,7); //bubble_sort(a,7); selectionsort(a,7); show_array(a,7); cout<<"Bubble counter = "<<bubble_counter<<endl; cout<<"Selection Counter = "<<selection_counter<<endl; return 0; } void show_array(int array[],int size) { for( int i=0 ; i<size; i++) { cout<<array[i]<< " "; } cout<<endl; } void bubble_sort( int array[],...
using the code above my instructor just want me to
delete name from a list of students name. the function needs to be
called delete_name. It's in c++. please no changing the code above
just adding. this is pointer and dynamic array.
// This is chapter 9 Pointers and Dynamic array #include< iostream> #include<string> using namespace std; //Gv //function declaration string* add_name(string*,int&); void display_names (string*,int); //main int main() //local var int size-3; string *students_names-new string[size]; //code cout<<"Enter "<<size< students names:"<<endl;...
Your task is to complete the following function/functions: 1. Given a position in the linked list, delete the node at that position.(Silver problem - Mandatory ) 2. Print the sum of all negative elements in the linked list.(Gold problem) If you want, you can refer to the the previous recitation manual (which was on Linked Lists) to implement node deletion. #include <iostream> using namespace std; //----------- Define Node --------------------------------------------------- struct Node{ int key; Node *next; }; //----------- Define Linked List...