c++ - Removing duplicates from an array, using dynamic mem. allocation -


this method member function of class sets(for college), has members,set(pointer) , card(int)(cardinality).i supposed remove duplicates , reduce allocated memory.

the nset pointer being used hold data temporarily.

unfortunately crashing, whenever called . wat do?

void remdup() {     int *nset;     for(int x=0;x<card-1;x++) {         for(int y=x+1;y<card;y++) {             if(set[x]==set[y]) {                 for(int g=y;g<card-1;g++) {                     set[g]=set[g+1];                 } card--;             }             }     }     nset=new int[card];     for( int u=0;u<card;u++) {         nset[u]=set[u];     }     delete set;     set=new int[card];     for(int u=0;card;u++) {         set[u]=nset[u];     } 

you have mistake in loop. for(intialization;condition;increment) {}

void remdup() {         int *nset;         for(int x=0;x<card-1;x++) {             for(int y=x+1;y<card;y++) {                 if(set[x]==set[y]) {                     for(int g=y;g<card-1;g++) {                         set[g]=set[g+1];                     } card--;                 }                 }         }         nset=new int[card];         for( int u=0;u<card;u++) {             nset[u]=set[u];         }         delete set;         set=new int[card];         for(int u=0;u<card;u++) {<---             set[u]=nset[u];         } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -