Question
(c++) Using the pseudo code listed below, extend it to include: * Reading data strings from a file * Convert from int based container to
(c++) Using the pseudo code listed below, extend it to include:
* Reading data strings from a file * Convert from int based container to templates or generics based * Accommodate dynamic resizing using this algorithm: 1. Starting with a dynamic size of 10, if the number of elements exceed this number: a. Reallocate the container size to double the current size b. Move the contents of the current container to the newly sized container c. Delete the previously sized container 2. Repeat from step 1a. as necessary 3. Note the data file is called "words.txt" (explained below)
---none of the previous answers to this question are correct on this site, so please don't copy/paste---
Resize C++
Data* ptemp = new Data[ size*2 ];
for (int i=0; i ptemp[i] = _mdata[i]; delete [] _mdata; _mdata = ptemp; capacity *= 2; <<<< DynamicArray Pseudo-code >>>> DynamicArray Class int* base // c++ int used = 0 int size = 0 DynamicArray(c) // constructor size(c) allocate(size) void allocate(c) size = c base = new T[size] for (i = 0 to size) base[i] = 0 void pop() for (i = 1 to used) base[i - 1] = base[i] void push(t) set(t) void set(v) base[used] = v used++ int get(offset) return base[used] int begin() return base[0] int end() return base[used - 1] int length() return used int capacity() return size words.txt is as follows. this code should work even if words.txt is changed to more words: when what there been one could very an who them Mr we now more out do are up
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started