Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++

#include <iostream>
using namespace std;

typedef int T;

T* add_entry(T* list, const T& new_entry,int& size);


void print_list(T* list, int size);

int main() {
    T* number_list = new T[3];
    number_list = {1,2,3};
    number_list = add_entry(number_list, 3, 3);
    print_list(number_list, 4);

}

T* add_entry(T* list, const T& new_entry,int& size) {
    T* new_list;
    for (int i = 0; i < size; i++) {
        new_list[i] = list[i];
    }

    new_list[size] = new_entry;

    delete[] list;

    return new_list;

}

void print_list(T* list, int size){
    for (int i = 0; i < size; i++)
        cout << list[i] << endl;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
1+2 =