Created
January 13, 2010 02:16
-
-
Save johnhmj/275863 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <cstring> | |
// Integrated Development Environment | |
// Visual C++ | |
using namespace std; | |
// | |
class CArr | |
{ | |
public: | |
CArr(size_t size); | |
~CArr(void); | |
void setValue(size_t pos, int val); | |
void Sort(void); | |
void Print(void); | |
private: | |
int* m_pointer; | |
size_t m_size; | |
}; | |
void main(int argc, char** argv) | |
{ | |
size_t len = 0; | |
cout<<"Input size of Array: ", cin>>len; | |
CArr arr(len); | |
for (size_t i = 0; i < len; i ++) | |
{ | |
int a = 0; | |
cout<<"Input value: ", cin>>a; | |
arr.setValue( i, a); | |
} | |
arr.Print(); | |
arr.Sort(); | |
arr.Print(); | |
system("PAUSE"); | |
} | |
CArr::CArr(size_t size) | |
{ | |
this->m_size = size; | |
if ( this->m_size == 0 ) | |
{ | |
this->m_pointer = NULL; | |
return; | |
} | |
this->m_pointer = new int[this->m_size]; | |
memset( (void*)this->m_pointer, 0, this->m_size); | |
} | |
CArr::~CArr(void) | |
{ | |
if ( this->m_pointer != NULL ) | |
{ | |
delete this->m_pointer; | |
} | |
} | |
void CArr::setValue(size_t pos, int val) | |
{ | |
if ( pos < this->m_size ) | |
{ | |
this->m_pointer[pos] = val; | |
} | |
} | |
void CArr::Sort(void) | |
{ | |
if ( this->m_pointer == NULL ) | |
{ | |
return; | |
} | |
for (size_t i = 0; i < this->m_size; i ++) | |
{ | |
for (size_t j = 0; j < this->m_size; j ++) | |
{ | |
if ( this->m_pointer[i] < this->m_pointer[j] ) | |
{ | |
int a = this->m_pointer[i]; | |
this->m_pointer[i] = this->m_pointer[j]; | |
this->m_pointer[j] = a; | |
} | |
} | |
} | |
} | |
void CArr::Print(void) | |
{ | |
for (size_t i = 0; i < this->m_size; i ++) | |
{ | |
cout<<" "<<this->m_pointer[i]; | |
} | |
cout<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment