Question
Can someone fix my code, template T* allocate(int capacity){ return new T[capacity]; } template T* reallocate(T* a, int size, int capacity){ T*walker = new T[capacity*2];
Can someone fix my code,
template
T* allocate(int capacity){
return new T[capacity];
}
template
T* reallocate(T* a, int size, int capacity){
T*walker = new T[capacity*2];
for (int i = 0; i
walker[i] = a[i];
}
return walker;
}
template
void print_array(T* a, int size, int capacity, ostream& outs){
for(int i = 0; i
outs
}
}
template
void print(T* a, unsigned int how_many, ostream& outs){
for (int i = 0; i
outs
}
outs
}
template
T* search_entry(T* a, int size, const T& find_me){
T*walker = a;
for(int i = 0; i
if(find_me == walker[i]){
return walker;
}
}
}
template
int search(T* a, int size, const T& find_me){
for(int i = 0; i
if (find_me == a[i]) {
return i;
}
}
}
template
void shift_left(T* a, int& size, int shift_here){
for (int i = shift_here; i
a[i - shift_here] = a[i];
}
for (int i = shift_here; i
a[i] = 0;
}
}
template
void shift_left(T* a, int& size, T* shift_here){
int b;
T*walker = a;
for (int i = 0; i
if(walker[i]==*shift_here) {
b = i;
break;
}
}
for (int i = b; i
walker[i-b] = walker[i];
}
for (int i = b; i
walker[i] = 0;
}
}
template
void shift_right(T *a, int &size, int shift_here){
for (int i = shift_here; i
a[i] = a[i-shift_here];
}
}
template
void shift_right(T *a, int &size, T* shift_here){
int b;
for (int i = 0; i
if(a[i]==*shift_here) {
b = i;
break;
}
}
for (int i = b; i
a[i-b]= a[i];
}
}
template
void copy_array(T *dest, const T* src, int many_to_copy){
for (int i = 0; i
dest[i] = src[i];
}
}
template
T* copy_array(const T *src, int size){
T*walker = new T[size];
for (int i = 0; i
walker[i] = src[i];
}
return walker;
}
template
string array_string(const T* a, int size){
for (int i = 0; i
cout
}
cout
return 0;
}
My output :
-- allocate(), print_array() ----- 0 10 20 30 40 50 60
-- search_entry() ----- 30 was found: 0 35 was found: -1817519720
-- copy function() (@@)----- void copy_array(dest, src, size): 0 10 20 30 40 50 60 T* copy_array(src, siae): 0 10 20 30 40 50 60
-- shift_right() - shift right at 30:0 10 20 30 40 50 60 - shift right at 60:0 10 20 30 40 50 60 - shift right at 0:0 10 20 30 40 50 60
-- reallocate() --- after reallocation: 0 10 20 30 40 50 60 - one more shift at 20: 0 10 20 30 40 50 60
-- shift_left() array now: 0 10 20 30 40 50 60 - shift left at 60:0 0 0 0 0 0 0 - shift left at 60:0 0 0 0 0 0 0 - shift left at 20:0 0 0 0 0 0 0 - shift left at 20:0 0 0 0 0 0 0
-- array_string() array now: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Segmentation fault: 11
Correct Output:
Will like helpful responses!!
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