Code snippet to Print a data from a binary tree – In-order(ascending)
// recursive version
Void PrintTree ( struct * node node )
{
if ( node == NULL )
return;
PrintTree(node - > left );
Printf(“%d”, node - > data);
PrintTree(node - > right );
}
Sunday, November 16, 2008
How to Print a data from a binary tree In ascending order
Posted by Nanya at 7:15 AM 0 comments
Labels: C-code
Tips for reducing unexpected buffer errors
When using functions such as strncpy() that take a size input parameter, you should use the size of the destination buffer and not the source buffer for correct functionality!
Following code snippet is an example of incorrect usage -
strncpy(dest, src, sizeof(src));
//If sizeof(src) > sizeof(dest) this would give unexpected results;
Therefore, the correct and safe usage should be,
memset(dest, 0, sizeof(dest)); //Fill the buffer with null characters
strncpy(dest, src, sizeof(dest)-1);
//sizeof(dest)-1 takes care of the space for the terminating null character
Posted by Nanya at 5:56 AM 0 comments
Sunday, November 9, 2008
C++ function to return Nth the node from the end of the linked list in one pass.
C++ function to return Nth the node from the end of the linked list in one pass.
Node * GetNthNode ( Node* Head , int NthNode )
{
Node * pNthNode = NULL;
Node * pTempNode = NULL;
int nCurrentElement = 0;
for ( pTempNode = Head; pTempNode != NULL; pTempNode = pTempNode->pNext )
{
nCurrentElement++;
if ( nCurrentElement - NthNode == 0 )
{
pNthNode = Head;
}
else
if ( nCurrentElement - NthNode > 0)
{
pNthNode = pNthNode - > pNext;
}
}
if (pNthNode )
{
return pNthNode;
}
else
return NULL;
}
Posted by Nanya at 12:58 PM 0 comments
Wednesday, October 29, 2008
Codd's Rules for Relational Database Management
The following are the 12Codd's rules for Relational Database Management!
If the first 5 are satisfied then the system is considered as a DBMS, and if 6 or more rules are being followed by the system, then it is regarded as an RDBMS!
•The information rule
•The rule of guaranteed access
•The Systematic treatment of all null values
•The database description rule
•Comprehensive data sub language
•The view updating rule
•The insert and update rule
•The physical independence rule
•The logical independence rule
•The integrity independence rule
•The distribution rule
•The Nonsubversion rule
Posted by Nanya at 1:41 PM 0 comments
Sunday, October 12, 2008
XML file for creation of a database of cricket players
save this as a .xml file...
< ?xml version="1.0" encoding="ISO-8859-1"? >
< ?xml-stylesheet type="text/xsl" href="cricket.xsl"? >
< Team >
< player >
< name > Sachin Tendulkar < /name >
< age > 35 < /age >
< role > Allrounder < /role >
< country > india < /country >
< runs > 12075 < /runs >
< batavg > 45.26 < /batavg >
< wickets > 234 < /wickets >
< matches > 333 < /matches >
< innings > 300 < /innings >
< highscore > 186 < /highscore >
< bestbowling > 5/29 < /bestbowling >
< /player >
< player >
< name > Shahid Afridi < /name >
< age > 34 < /age >
< role > Batsman < /role >
< country > pakistan < /country >
< runs > 3752 < /runs >
< batavg > 40.26 < /batavg >
< wickets > 154 < /wickets >
< matches > 200 < /matches >
< innings > 173 < /innings >
< highscore > 107 < /highscore >
< bestbowling > 5/34 < /bestbowling >
< /player >
< player >
< name > Jacques Kallis < /name >
< age > 31 < /age >
< role > Allrounder < /role >
< country > South Africa < /country >
< runs > 5752 < /runs >
< batavg > 40.26 < /batavg >
< wickets > 89 < /wickets >
< matches > 186 < /matches >
< innings > 140 < /innings >
< highscore > 167 < /highscore >
< bestbowling > 5/45 < /bestbowling >
< /player >
< player >
< name > Ricky Ponting < /name >
< age > 36 < /age >
< role > Batsman < /role >
< country > australia < /country >
< runs > 9876 < /runs >
< batavg > 45.48 < /batavg >
< wickets > 1 < /wickets >
< matches > 325 < /matches >
< innings > 297 < /innings >
< highscore > 161 < /highscore >
< bestbowling > 1/36 < /bestbowling >
< /player >
< /Team >
Posted by Nanya at 12:24 PM 0 comments