Basically we have to have an insert, delete, and print methods. When inserting, it is supposed to automatically sort the array without a sorting algorithm (using 2 arrays). I keep doing trial and error to no success. I understand pointers and references but it is weird to me coming from Java.

Any help would be appreciated.

#include "stdafx.h" #include <iostream> #include <iomanip> using namespace std; void display(int* arr,int *numptr,int sz) { cout << "The array is: [ "; for (int i = 0; i < sz; i++) cout << arr[i] << ' '; cout << "]" << endl; } int insert(int* arr, int*& numptr,int& sz) { int *arrNew = new int[sz+1]; for (int i = 0; i < sz; i++) { if (arr[i] < *numptr) { arrNew[i] = arr[i]; } else { arrNew[i] = *numptr; sz++; } } return *arrNew; } void removeIt(int* arr, int*& numptr, int& sz) { for (int i = 0; i < sz - 1; i++) { if (arr[i] == *numptr) { arr[i]=arr[i+1]; } if (sz>i+2) arr[i+1] = arr[i+2]; } sz--; } int _tmain(int* argc, _TCHAR* argv[]) { int choice; int number; int *numptr = &number; int sz = 1; // you say in your comments to start with an array of 0 or 1 length, here it is. arr[sz] is arr[1] initially; int *arr = new int[sz]; L1: cout << "Press 1 to insert a number into an array" << endl << "Press 2 to remove a number into an array" << endl << "Press 3 to print the array" << endl << "Press 0 to quit" << endl; cin >> choice; if (choice==1) { cout << "What number do you want to insert?" << endl; cin >> number; //sz++; int arr = insert(&arr,numptr,sz); goto L1; } if (choice==2) { cout << "What number do you want to delete?" << endl; cin >> number; removeIt(arr,numptr,sz); // make sure that if the number does not exist, dont freak out; goto L1; } if (choice==3) display(arr,numptr,sz); if (choice=0) return 0; else return 0; }