Can you show me a simple code to add a node after the current one? Please I need your help.
Can you show me a simple code to add a node after the current one? Please I need your help.
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
heres one from something i was doing earlier. Pervert it to your needs.
Code:Node* NewNode(char* Value,size_t Len) { Node* NodePtr=malloc(sizeof (Node)); if(!NodePtr) Bail(); NodePtr->Value=malloc(Len); if(!NodePtr->Value) { free(NodePtr); Bail(); } strcpy(NodePtr->Value,Value); NodePtr->Next=NULL; return NodePtr; } /* Adds a node to the tail of the list so list will act as a queue */ Node* AddNode(Node* Head,char* Value,size_t Len) { Node* Current; Node* New=NewNode(Value,Len); if (!Head)Head=New; else { Current=Head; while(Current->Next != NULL) Current=Current->Next; Current->Next=New; } return Head; }
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Here's some simple code to insert node t after node x.
-PreludeCode:void insertNode ( node *x, node *t ) { t->next = x->next; x->next = t; }
My best code is written with the delete key.
Ok, I am back to square one the same problem I had when I was reading the tutorial........take a look at the image I've attached where I've tried to recreate that linked list, I have a question on that one.
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
-PreludeCode:Start: Node-->x-->Node-->Node t-->NULL t->next = x->next; Node-->x-->Node-->Node | t---^ x->next = t; Node-->x Node-->Node | | t---^ End: Node-->x-->t-->Node-->Node
My best code is written with the delete key.
sorry but that got me a little confused but I mean is the graphic that I posted the right idea? or am I going all wrong about i?
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
>or am I going all wrong about i?
Got it in one. Don't think of t as already being a part of the list, it's completely separated so the first statement will assign t's next pointer to point at the node that x points to. The second statement causes t to be fully inserted in the list by pointing x's next pointer to t.
The end result is that t is insterted right between x and the node that x points to. I promise it's not as hard as it sounds, just difficult to explain. Get out some change from your pocket/purse and make a list out of them, then insert a coin.
Quarter--Nickel--Penny
Work it out so that you insert a dime between the quarter and nickel using the code I gave you. The quarter is x and the dime is t, that's how I figured out linked lists.
-Prelude
My best code is written with the delete key.
Hold one this is read from LEFT TO RIGHT or FROM RIGHT TO LEFT?
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
Left to right
-Prelude
My best code is written with the delete key.
oooooooooooooooooooooooh damn now I know that.
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
house->driveway=apartment->driveway;
apartment->driveway=house;//for some reason I see this as being the joining link between the house and the apartment, this being the driveway.
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
Please I just want to know if this is right before I go to bed and see if I can get some sleep.
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.
>house->driveway=apartment->driveway;
>apartment->driveway=house;
The apartment is first, the apartment's driveway leads to the house. The house's driveway leads to whatever the apartment's driveway lead to before the house got in the way.
This is not a very good abstraction because you think in construction terms and no sane contractor would build things like this.
>//for some reason I see this as being the joining link between the house and the apartment
It is, the joining link from the apartment to the house to be precise. But driveways aren't good as links because a driveway should be a link from the house to the road or the apartment to the road, not the apartment to the house. But if this confuses you just ignore it because I'm blabbering now.
-Prelude
My best code is written with the delete key.
Thanks both Stoned_Coder and Prelude
There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!
"...The only real game I thank in the world is baseball..." --Babe Ruth
"Life is beautiful"-Don Corleone right before he died.
"The expert on anything was once a beginner" -Baseball poster I own.
Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.