Sunday 30 September 2012

Classical Programming - 5 : exchange sort (c++)

void ExchangeSort(int* pData,int Count)
{
    int iTemp;
    for(int i=0;i<Count-1;i++) {
          for(int j=i+1;j<Count;j++) {
              if(pData[j]<pData[i])   {
                         iTemp = pData[i];
                         pData[i] = pData[j];
                         pData[j] = iTemp;
                  }
              }
         }
   }

Saturday 29 September 2012

Classical Programming - 4 : bubble sort (c++)

void BubbleSort(int* Data,int Count) {
    int iTemp;
    for(int i=1;i<Count;i++) {
          for(int j=Count-1;j>=i;j--) {
                if(Data[j]<pData[j-1]) {
                        iTemp = Data[j-1];
                        Data[j-1] = pData[j];
                        Data[j] = iTemp;
                     }
              }
        }
 }



Tuesday 13 March 2012

Classical Programming - 3 : print binary numbers (c++)

#include <iostream>
using namespace std;
#define SIZE sizeof(int)*8

char* bits(int val) {
     static char str[SIZE];
     for(int i = SIZE-1; i >= 0; i--) {      
       str[(SIZE-1)-i] = (val & (1<<i)) == 0? '0':'1';
     }
     return str;
 }

int main () { 
    int i = 2345;   
  
    cout << " i: " << bits(i) << endl;  
    return 0;
}

Monday 12 March 2012

Classical Programming - 2 : check bit of unsigned integer (c++)

bool isOn(unsigned int val, int bitNo){
  return (val>>bitNo)%2;
}

bool isOff(unsigned int val, int bitNo){
  return !isOn(val, bitNo);
}

Sunday 12 February 2012

Classical Programming - 1 : validation (c++)

int validMonth(int mon, char* errmes){
  int res = 0;
  if(mon > 0 && mon <=12){
    res  = 1;
  }
  else{
    strcpy(errmes, "Invalid month (1<=month<=12)");
  }
  return res;
}
write the above function in one line:
int validMonth(int mon, char* errmes){
return (mon>0&&mon<=12)||(strcpy(errmes, "Invalid month (1<=month<=12)")&& 0);
}

Monday 9 January 2012

How to Improve Your Study Habits

       Perhaps you are an average student with average intelligence. You do well enough in school, but you probably think you will never be a top student. This is not necessarily the case, however. You can receive better grades if you want to. Yes, even students of average intelligence can be top students without additional work. Here's how:
    1. Plan your time carefully.
    2. Find a good place to study.
    3. Skim before you read.
    4. Make good use of your time in class.
    5. Study regularly.
    6. Develop a good attitude about tests.
    There are other techniques that might help you with your studying. Only a few have been mentioned here. You will probably discover many others after you have tried these. Talk with your classmates about their study techniques. Share with them some of the techniques you have found to be helpful. Improving your study habits will improve your grades.