resizine arrays

ok i was wondering if i could resize an array by taking an array pointer and copying it and new items in to an array than deleting the only array and putting the new one in it... heres my attempt

1
2
3
//i have this passing in to it, its in the main method

 student *array = new student[x];


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int delOne(student *k, int x)
  {
      int t = x-1;
      student *newArray = new student[t];
      cout<< "which student would you like to delete from the list" << endl;
      for(int i = 0; i < x; i++)
      {
              cout <<i << ") " << k[i].id << endl;
              }
      int mp;        
      cin >> mp;
      int z = 0;
      for(int i = 0; i < x; i++)
      {
              if(i == mp)
              {continue;}
              z++;
              newArray[z] = k[i];
              }  
      delete k;    //delete old array
      k=newArray; //save new downsized array
      return z;  //return the size of the array for further use
      }


frankly its not working and im wondering why?
well i noticed its probably because i don't increase the size of x but i cant seam to figure out where i should do that
Last edited on
Do you hear that? That's the sound the wheel makes when it's reinvented.

http://www.cplusplus.com/reference/stl/vector/
Last edited on
cant use vectors lol or i would have dune that already lol or link list for that matter
Last edited on
so what i ended up doing was just putting everything in the same place in the main method so i could edit x easer

ew sloppy well ill fix it later i gotta turn it in now
Last edited on
Topic archived. No new replies allowed.