Sunday, April 15, 2012

Tree


#include
#include
#include
#include

class Node
{
private:
    Node* _left;
    Node* _right;
    int _data;

    void _AddNode(Node*& _nodeRef, int i)
    {
    if(_nodeRef)
    {
delete _nodeRef;
}
_nodeRef = new Node(i);
}

void _DeleteNode(Node*& _nodeRef)
{
if(_nodeRef)
   delete _nodeRef;
    }

public:
    Node(int i=0, Node* _left=0, Node* _right =0):_left(left),_right(right),_data(i) {}
    ~Node()
    {
}

    void AddLeftNode(int i=0)
    {
        _AddNode(_left,i);
    }

    void AddRightNode(int i=0)
{
   _AddNode(_right,i);
    }

    void AddNode(int i=0)
    {
Node** temp = &this;

while(*temp!=NULL)
{
if(*temp->_data <= i)
temp = &(*temp)->_left;
else
temp = &(*temp)->_right;
}

*temp = new Node(i);
}

Node* Left()
{
return _left;
}

Node* Right()
{
return _right;
}

    void DeleteLeft()
    {
_DeleteNode(_left);
}

void DeleteRight()
{
_DeleteRight(_right);
}

void SetData(int i=0)
{
_data = i;
}

int Data()
{
return _data;
}

};

void PreOrderTraversalRecuresive(Node* node)
{
//Visit Root
//Visit Left
//Visit Right


if(!node)
return;

cout << node->Data() << " ";
PreOrderTraversalRecuresive(node->Left());
PreOrderTraversalRecuresive(node->Right());
}

void InOrderTraversalRecuresive(Node* node)
{
//Visit Left
//Visit Root
//Visit Right

//returns elems in ascending order

if(!node)
return;

InOrderTraversalRecuresive(node->Left());
cout << node->Data() << " ";
InOrderTraversalRecuresive(node->Right());
}

void PostOrderTraversalRecuresive(Node* node)
{
//Visit Left
//Visit Right
//Visit Root

if(!node)
return;

PostOrderTraversalRecuresive(node->Left());
PostOrderTraversalRecuresive(node->Right());
cout << node->Data() << " ";
}

void PreOrderTraversalIterative(Node* node)
{
if(!node)
return;

std::stack nodeStack;

Node* temp;

nodeStack.push(node);

while(!nodeStack.empty())
{
temp = nodeStack.top();
cout << temp->Data() < " ";
nodeStack.pop();
temp->Right()?nodeStack.push(temp->Right()):0;
temp->Left()?nodeStack.push(temp->Left()):0;
}
}

void InOrderTraversalIterative(Node* node)
{
if(!node)
return;

std::stack nodeStack;
Node* temp=node;

nodeStack.push(temp);

while(!nodeStack.empty())
{
while(!nodeStack.top()->Left())
{
nodeStack.push(temp->Left());
}

cout << nodeStack.top()->Data() < " ";
nodeStack.pop();

temp = nodeStack.top();

cout << temp->Data() << " ";
nodeStack.pop();

temp->Right()?nodeStack.push(temp->Right()):0;
}
}

void PostOrderTraversalIterative(Node* node)
{
if(!node)
return;

std::stack nodeStack;
Node* temp=node;

nodeStack.push(temp);

while(!nodeStack.empty())
{
while(!nodeStack.top()->Left())
{
nodeStack.push(temp->Left());
}

cout << nodeStack.top()->Data() < " ";
nodeStack.pop();

temp = nodeStack.top();

temp->Right()?nodeStack.push(temp->Right()):0;
}
}

void BreadthFirstTraversalIterative(Node *node)
{
if (!node)
return;

std::queue nodeQueue;
Node* temp = node;

nodeQueue.push(node);

while(!nodeQueue.empty())
{
temp = nodeQueue.top();
nodeQueue.pop();
cout << temp->Data() << " " ;

temp->Left()?nodeStack.push(temp->Left()):0;
temp->Right()?nodeStack.push(temp->Right()):0;
}
}
void DepthFirstTraversalRecursive(Node* node)
{
if (!node)
return;

cout << node->Data() << " " ;
Node* temp;

if(node->Left())
temp = node->left();
else if(node->Right())
temp = node->Right();
else
temp = NULL;

DepthFirstTraversalRecursive(temp);
}

void DepthFirstTraversalIterative(Node* node)
{
if(!node)
return;

std::stack nodeStack;
Node* temp=node;

nodeStack.push(temp);

while(!nodeStack.empty())
{
while(!nodeStack.top()->Left())
{
nodeStack.push(temp->Left());
}

cout << nodeStack.top()->Data() < " ";
nodeStack.pop();

temp = nodeStack.top();

temp->Right()?nodeStack.push(temp->Right()):0;
}
}

int DepthOfTree(Node *node)
{
if(!node)
return 0;

int h1 = DepthOfTree(node->Left());
int h2 = DepthOfTree(node->Right());

return (h1 > h2)?h1+1:h2+1;
}

Node* FillTree(char* fileName)
{
if(!fileName)
return NULL;

ifstream ifp;

if(!ifp.open(fileName))
return NULL;

int data;

ifp >> data;

Node* node = new Node(data);

while(!ifp.eof())
{
ifp >> data;
node->AddNode(i);
}

ifp.close();
}

int main(int argc, char** argv)
{
PreOrderTraversalRecuresive();
InOrderTraversalRecuresive();
PostOrderTraversalRecuresive();

PreOrderTraversalIterative();
InOrderTraversalIterative();
PostOrderTraversalIterative();

BreadthFirstTraversal();
DepthFirstTraversalRecursive();
DepthFirstTraversalIterative();

DepthOfTree();
}

Monday, May 10, 2010

చేదు పాట

శ్రీ శ్రీ గారి శత జయంతి సంధర్భంగా, ఆయన రాసిన, నాకు నచ్చిన "మహాప్రస్థానం" లోని ఒక చిరు కవిత ...

ఔను నిజం, ఔను నిజం,
ఔను నిజం, నీ వన్నది,
నీ వన్నది, నీ వన్నది,
నీ వన్నది నిజం, నిజం!

లేదు సుఖం, లేదు సుఖం,
లేదు సుఖం జగత్తులో!
బ్రతుకు వృధా, చదువు వృధా,
కవిత వృధా! వృధా, వృధా!

మనమంతా బానిసలం,
గానుగలం, పీనుగులం!
వెనుక దగా, ముందు దగా,
కుడి ఎడమల దగా, దగా!

మనదీ ఒక బ్రదుకేనా?
కుక్కలవలె, నక్కలవలె!
మనదీ ఒక బ్రదుకేనా?
సందులలో పందులవలె!

నిజం సుమీ, నిజం సుమీ,
నీ వన్నది నిజం సుమీ,
బ్రతుకు ఛాయా, చదువు మాయ,
కవిత కరక్కాయ సుమీ!

లేదు సుఖం, లేదు రసం,
చేదు విషం జీవఫలం!
జీవఫలం చేదు విషం,
చేదు విషం, చేదు విషం!

ఔను నిజం, ఔను సుమా,
ఔను నిజం నీ వన్నది!
నీ వన్నది, నీ వన్నది,
నీ వన్నది నిజం,నిజం!

-- శ్రీ శ్రీ

Thursday, April 15, 2010

దేని కోసం?

శ్రీ శ్రీ గారి పద కవితా స్ఫూర్తితో ,

వేళ కాని వేళలలో,
దారి కాని దారులలో,
కానరాని కాంక్షలతో,
దేనికోసమీ దేవులాట !

ఆకలితో అలసటతో,
ఎందుకోసమీ ప్రాకులాట !

నిశీధి రాతిరి హోరు గాలిలో,
చావు పుట్టుకల పొలిమేరల్లో,
అవ్యక్తపు ఊహలతో,
ఎందుకీ నిర్లిప్తత !

ప్రపంచమంతా నిదురొన్న నడి రాతిరి,
నీలోనే నీకేదో ఆవేదన.. ?

ఎందుకీ అన్వేషణ ?
ఎక్కడికీ ప్రస్థానం ?

Tuesday, April 13, 2010

Welcome to hell

  • Life starts with a cry, clearly signifying the arrival in hell.
  • Trouble starts from the day of birth when the newly born starts crying. Signifying that the newly born was suddenly forced into hell.
  • No one allows the baby to have its own way. No one will try to think what the baby needs. Every day feeding and every other behavior follows a pattern that was pre-defined. No one can see what's in the mind of the baby.
  • As the baby grows up and walks, lots of controls come into picture. People say that it is for the safety of the child only that there are controls. Of course from the point of view of the elders they are doing the right thing. Who cares what the child thinks? The child dislikes the control and wants freedom. After all, the child did not ask to be brought into the world.
  • As the child grows up, he/she is forced into the school in spite of the reluctance of the child. He/she is forced to follow a set pattern defined by the society. The child is told that it is important to follow the set pattern for its own future.
  • As the child becomes adult, freedom is further curtailed by numerous laws. The adult cannot even get food without working, and for getting a job, the adult has to struggle a lot. Comparisons are made by the parents with other colleagues who get a better job. All the pressure forces the adult to get a job. Not sure if there is job satisfaction.
  • There will be lot of struggle to hold ones place wherever one works. For deviation comes the love life. That will start another phase in life of contradictions and struggle.
  • Next the parents become old. There will be sadness all around. All the old age people who were young earlier dies.
  • Finally the very baby that came unknowingly into the world grows old and death will any way come.
  • Why is all this required? Why struggle all your life when finally what actually happen in life for everyone anywhere are birth, struggle, stress, sadness and death. Knowing very well all these problems in life, why hell should people continue the cycle? That means people are not reluctant to throw someone into this hell when they have every chance to prevent the same.

Tuesday, January 12, 2010

రింగ రింగ

A brainchild of creative heads during the return journey from Wayanad ...

Creative Director _____ : Harish Kumar Reddy
Composer & Editor ____ : Raghuram Neela
Lyricist ____________ : Phani Kumar Ravi
Critic ______________ : Pavan KVV
Author & Coordinator __ : Sunil Paduchuru

రింగ
రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే ||4||

పాశు పాశు కుర్రాలము మేము...
ఆంధ్రా నుంచి వచ్చేసాము...
రింగ రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||

మస్తుగున్న కుట్టీల కోసం...
పుబ్బులన్నీ వదిలేసాము...
రింగ రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||

తెల్ల క్యాబ్ ఎక్కి ఎక్కి బోరే కొట్టి...
నీళ్ళ బస్సు మీద మాకు మోజే పుట్టి...
మదికేరి చేరినాము, చేరి ఎదురు చూసినా...
ఎవరి కోసం?

సిటీ పోరిలంటే మాకు బోరే కొట్టి ...
పల్లె కుట్టిల కోసం ఆరా తీసి ...
గోకర్ణ కెళ్లినాము ...
కొన్నూరూ
కెళ్లినాము ...
రేపల్లె
కెళ్లినాము ...
మంగళూరు కెళ్లినాము ...
వాయనాడుకి వచ్చి మేము సెట్ అయ్యాము ...

ఓహో, మరి ఇక్కడ కుట్టిలేలా ఉన్నారు ???

మలయాళీ మర్దన చేతులతో చేసి ...
మాలో ఆశలని పెంచేశారు ...
అమ్మనీ ...
రింగ రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||

రింగ రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||

వాయించు ఎహే...

ఇదిగో కుర్రాళ్ళు...
అదంతా సరే గాని ...
అసలు ఈ రింగ రింగ గోలేంటి ...

అసలుకేమో ఆ హెయిర్ స్టైల్ ...
"కల్పెట్ట ఎద్దిక్కల్ రింగ"
రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||
పలకలేక మేమేట్టినాము ...
పెట్ నేము రింగ రింగా ...
రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||
జీన్సు తీసి కట్టినాము లుంగీ పంచ ...
స్నానం చేసి పూసి నాము పౌడర్ బాగా ...
"Geek" లాగ ఉన్న మమ్ము ...
మార్చినారు వీక్ గా ...

అచ్చులన్ని మార్చినారు "అళ" కారంగా ...
ఆకు కూర మార్చినారు "ఫిష్" కారంగా ...

Monday, December 28, 2009

రింగా రింగా...

A brainchild of creative heads during the return journey from Wayanad ...

Creative Director _____ : Harish Kumar Reddy
Composer & Editor ____ : Raghuram Neela
Lyricist ____________ : Phani Kumar Ravi
Critic ______________ : Pavan KVV
Author & Coordinator __ : Sunil Paduchuru

రింగ
రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే ||4||

పాశు పాశు కుర్రాలము మేము...
ఆంధ్రా నుంచి వచ్చేసాము...
రింగ రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||

మస్తుగున్న కుట్టీల కోసం...
పుబ్బులన్నీ వదిలేసాము...
రింగ రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||

తెల్ల క్యాబ్ ఎక్కి ఎక్కి బోరే కొట్టి...
నీళ్ళ బస్సు మీద మాకు మోజే పుట్టి...
మదికేరి చేరినాము, చేరి ఎదురు చూసినా...
ఎవరి కోసం?

సిటీ పోరిలంటే మాకు బోరే కొట్టి ...
పల్లె కుట్టిల కోసం ఆరా తీసి ...
గోకర్ణ కెళ్లినాము ...
కొన్నూరూ
కెళ్లినాము ...
రేపల్లె
కెళ్లినాము ...
మంగళూరు కెళ్లినాము ...
వాయనాడుకి వచ్చి మేము సెట్ అయ్యాము ...

ఓహో, మరి ఇక్కడ కుట్టిలేలా ఉన్నారు ???

మలయాళీ మర్దన చేతులతో చేసి ...
ఒంట్లో వేడిని పెంచేశారు ...
అమ్మనీ ...
రింగ రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||

బొడ్డు కింద లంగాను చుట్టి ...
మాలో లావాను పెంచేశారు ...

రింగ రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||

వాయించు ఎహే...

ఇదిగో కుర్రాళ్ళు...
అదంతా సరే గాని ...
అసలు ఈ రింగ రింగ గోలేంటి ...

అసలుకేమో ఆ హెయిర్ స్టైల్ ...
"కల్పెట్ట ఎద్దిక్కల్ రింగ"
రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||
పలకలేక మేమేట్టినాము ...
పెట్ నేము రింగ రింగా ...
రింగ రింగ రింగ
రింగ రింగ రింగా రింగారే
||2||
జీన్సు తీసి కట్టినాము లుంగీ పంచ ...
స్నానం చేసి పూసి నాము పౌడర్ బాగా ...
"Geek" లాగ ఉన్న మమ్ము ...
మార్చినారు వీక్ గా ...

అచ్చులన్ని మార్చినారు "అళ" కారంగా ...
ఆకు కూర మార్చినారు "ఫిష్" కారంగా ...


Onti loni water antha chemata laaga pindinaru..
Vompu loni atharantha aaviralle peelchinaru..
Vompi vompi sompulanni tagesaru..
ai baboi tagesara inkem chesaru..

Puttu machalu lekkettesaru..
Leni machalu puttincharu

Ringa ringa Ringa ringa

Unna kolathalu marchesinaru..
Raani madathalu rappincharu..
Ringa ringa Ringa ringa

Idigo foreign ammai..
Ela undeti mana kurralla power
Pancha kattu kurrallaloni..
Punch naku thelisochindi..
Ringa ringa Ringa ringa

Muntha kallu laginchetolla..
Strengthu naku tega nachindi..
Ringa ringa Ringa ringa

Neeti bed sarasamante garru garru..
Mulakamanchamante inka kirru kirru..
Surrumanna scenelanni phone lo friends thoti cheppinaa Chepina
Chepesavetti..

Five star hotel ante kacha picha..
Pampu settu matter ite racho rachaa..
Annamata cheppagane ..
Ireland’u greenland’u newzeland’u..
Netherland’u thailand’u phinland’u..
anni landula papaleeda land ayyaru..

landayyara mari memem cheyyali
Hand meeda handeseyyandi..
Landu kabja cheseyyandi..
Ringa ringa Ringa ringa

Hand meeda handesesthame..
landu kabja chesesthamey
Ringa ringa Ringa ringa



Monday, August 3, 2009

Obsessed with Mac? Install XP with Mac OSX dual boot

This post is dedicated to all those disheartened souls who are very much obsessed with the creativity of Mac but couldn't afford to buy one because of reasons unexplained. Atleast I couldn't afford to by Mac Air inspite of it being the most wanted model. With the launch of Leopard OSX, Apple provides a brief respite for all the Mac lovers. By adapting its software to x86 architecture, Apple thus supports its software to run on x86 supported hardware.

To put it in short, now one can install any kind (Linux/Windows) of OS on Apple Mac Books and install Mac OS X on any kind of hardware with dual boot or triple boot facility.

After much struggle, I put down this guide to for all Mac lovers to install OSX on their laptops.

This guide is strictly for INTEL 32-bit Processors only. I have not tried installing OSX on other processors.

I strongly suggest you to backup your Primary Partition (like C Drive) with some tools like Symantec Ghost before proceeding any further. If you miss any one of the steps listed below you may screw up your master boot record and may end up with two non-working Operating Systems installed on your system.

What all you need:

1) Some kind of Ghost software to back up your primary drive
2) Kalyway 10.5.2 DVD (Either download it from torrents or you can have it from me)
3) GParted Live CD (download the first one)
4) One blank DVD and one blank CD/USB Memory Stick
5) A bootable WinXP CD (only if any thing goes wrong)

Disclaimer: (Pasted as is from wiki.osx86project.org)

I am NOT responsible for anything that happens to your system. This is a relatively easy process, but if you mess up with the partitioning you could POTENTIALLY cause damage to your drive! Follow these instructions to the letter and you should be fine, BACKUP YOUR IMPORTANT FILES! Don't mess around with the install!

Don't let that put you off though, having one of these is a great experience.
If you enjoy the final outcome, consider donating to the Kalyway team or even more importantly, buy a license. (Ofcourse we will never do that.. ;))

Note: I did not backup my files, screwed up my MBR and had to format my primary drive. So I strongly suggest you to backup your important files.

Installation Process:

**I assume you have a fully functional Windows XP istalled on your laptop.

**Create a new partition for installing OSX. Make sure the new partition is also a primary partition (primary but not active partition)

**Make sure you are installing OSX on a primary partition but not extended partition

OS X Install

  1. Now we get to the cooler part of the install. Put your Kalyway disk in your drive and restart your computer.
  2. If your computer boots back into XP, change your boot order settings to read from the DVD before the hard drive.
  3. when you get to the screen that says “starting Mac OS X installer”, press the F8 key on your keyboard.
  4. then type “-v” (no quotes) and hit enter.
  5. The DVD will now boot into the Installer for OS X. Be patient as this can take a while.
  6. After the installer starts up, hit the arrow and wait for the Welcome screen to pop-up.
  7. Now, before you hit continue, at the top of the screen click on the menu that says ‘Utilities’, then click on ‘Disk Utility’.
  8. When the disk utility comes up, you should see on the left side of the screen your hard disk.
  9. Select the partition that you are going to install OS X on. Make sure the partition you select is not your Windows
  10. partition. You can make sure of this by checking the file format of the partition in the bottom-left portion of the window.
  11. Once you have the correct partition selected press the tab that reads ‘Erase’.
  12. In the drop-down menu select ‘Mac OS X (Journaled)’ and name it something simple like ‘osx’ or ‘leo’. DO NOT use a “space” in the name or any other special characters such as % or &.
  13. Press Erase and press it again in the pop-up.
  14. Close out of the Disk Utility by clicking on the red button in the top left corner of the window.
  15. You’ll now see that you are returned to the Welcome screen. Click Continue and agree to the Licence.
  16. In the Installation destination screen select the partition you just made. Click Continue.
  17. Now click the customize button.
  18. At the bottom open up the sub-selection menu and de-select the bootloader for GUID. Then select the bootloader for MBR. This is the MOST important part of the entire install! If you do not select MBR, you will be stuck with a non-working install!
  19. Close the customization window.
  20. Click Install. (You can skip the media check if you wish.)
  21. At this point depending on the amount of RAM you have, and the speed of your processor, The install can take almost 15 mins.

Boot Loader Configuration

  1. After the Installation has completed, restart your computer with the Gparted Live CD in the drive.
  2. Press enter for all the defaults whenit asks. (Unless, of coarse, you have a different keyboard layout.)
  3. When the graphical interface is done loading, find your Windows partition (it will be formated as NTFS.) and click on it.
  4. Now right click it, and choose “Flags”
  5. Now place a check mark in the “boot” checkbox.
  6. Close the window, and click Exit. As your computer restarts, remove the Gparted CD from your drive and boot into XP.
  7. Once in XP open up My Computer and go into your C: Drive.
  8. If it says that the fles on this drive are protected, just click the continue button.
  9. In the Menu bar click Tools –> Folder Options
  10. Click the view tab in the new window.
  11. Check Hide protected System Files and Show Hidden Files and Folders.
  12. Now Close that window and go back to your drive. Open the file named boot.ini or just boot.
  13. copy this into the last line of text C:\chain0="Mac OS X86"
  14. Save and close the file.
  15. Put your Kalyway DVD in your drive.
  16. Copy the file called “chain0″ to your C: drive.
  17. Close and restart without the Kalyway in your drive.

Congratulations! You should now see an option to boot XP or Mac OSX 86! Choose which one you would like and boot.

If you are having trouble leave a comment and I’ll help!

For complete details please go through the link pasted below. The credits go to the original content writer.

http://maconpc.distinctlyjordan.com/2008/03/20/how-todual-boot-xp-and-leopard/