Problem z dynamiczną dwuwymiarową tablicą.
Ostatnio zmodyfikowano 2013-07-20 19:54
Bimbol Temat założony przez niniejszego użytkownika |
» 2013-07-20 19:17:18 Szczerze, to już nie mam pojęcia jak to zrobić. Można prosić o jakiś przykład? |
|
pekfos |
» 2013-07-20 19:24:19 void ChangeSize( unsigned Index1, unsigned Index2 ) { int ** Array = new int *[ Index1 ]; for( unsigned i = 0; i < Index1; ++i ) Array[ i ] = new int[ Index2 ]; for( unsigned i = 0; i < Index1; ++i ) { memcpy( Array[ i ], m_Table[ i ], sizeof( int ) * Index2 ); delete[] m_Table[ i ]; } memcpy( Array, m_Table, sizeof( int ) * Index1 ); delete[] m_Table; m_Table = Array; m_Index1 = Index1; m_Index2 = Index2; }
|
|
Bimbol Temat założony przez niniejszego użytkownika |
» 2013-07-20 19:54:41 Dzięki wielkie teraz działa :) Gdyby ktoś kiedyś potrzebował: void ChangeSize( unsigned Index1, unsigned Index2 ) { int ** Array = new int *[ Index1 ]; for( unsigned i = 0; i < Index1; ++i ) Array[ i ] = new int[ Index2 ]; if( Index1 < m_Index2 ) for( unsigned i = 0; i < Index1; ++i ) { if( Index2 < m_Index2 ) memcpy( Array[ i ], m_Table[ i ], sizeof( int ) * Index2 ); else memcpy( Array[ i ], m_Table[ i ], sizeof( int ) * m_Index2 ); delete[] m_Table[ i ]; } else for( unsigned i = 0; i < m_Index1; ++i ) { if( Index2 < m_Index2 ) memcpy( Array[ i ], m_Table[ i ], sizeof( int ) * Index2 ); else memcpy( Array[ i ], m_Table[ i ], sizeof( int ) * m_Index2 ); delete[] m_Table[ i ]; } delete[] m_Table; m_Table = Array; m_Index1 = Index1; m_Index2 = Index2; } |
|
1 « 2 » |