its writen on the code i dont know how to pass that to c the info of the ptemp->link :)
Main Topics
Browse All Topicsi fixed the problems thanks :) but now i have a new question on ordered insertion on a ordered list.
void ordered_insert(void)
{
NODE* new;
NODE* ptemp;
new = new_node();
read_node(new);
if(new <= first)
{
new->link = first;
return new;
}
ptemp = first;
while((new->data(?)ptemp->
{
ptemp = ptemp->link;
}
new->link = ptemp->link;
ptemp->link = new;
// return first;
}
sorry for my bad english :)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> if(new <= first)
Why are you comparing pointers like this ? There's no point, nor is it reliable. Maybe you intended to compare the data member of the node ?
>> // in here how do get infomation of the info[link[ptemp]]
Since 'data' is a char*, use strcmp to compare the data member of the new node with the data member of the current node :
http://cplusplus.com/refer
void ordered_insert(void)
{
NODE* new;
NODE* ptemp;
new = new_node();
read_node(new);
if(strcmp(new->data, prim->t) can i do this?
{
new->link = first;
return new;
}
ptemp = first;
while((strcmp(new->data, ptemp->link)>0) && (ptemp->link != NULL))
{
ptemp = ptemp->link;
}
new->link = ptemp->link;
ptemp->link = new;
// return first;
}
is this correct? im kinda lost a bit here :P
>> if(strcmp(new->data, prim->t) can i do this?
What's prim-> t ?
You're also missing the actual <= check.
>> return new;
The function is defined to return void ... so you can't return anything. Instead, you should probably set 'first' to point to the new node.
>> while((strcmp(new->data, ptemp->link)>0) && (ptemp->link != NULL))
Here you're using strcmp to compare a char* with a NODE*. strcmp is used for comparing two char*'s.
Also, check whether ptemp->link is NULL BEFORE dereferencing it.
>> is this correct? im kinda lost a bit here :P
You're close :)
void ordered_insert(void)
{
NODE* new;
NODE* ptemp;
new = new_node();
read_node(new);
if(strcmp(new->data, prim->ptemp) <= 0)
{
new->link = first;
return new;
}
ptemp = first;
while((strcmp(new->data, ptemp->link) <= 0) && (ptemp->link != NULL))
{
ptemp = ptemp->link;
}
new->link = ptemp->link;
ptemp->link = new;
first = new;
}
how is it now? :)
void ordered_insert(void)
{
NODE* new;
NODE* ptemp;
new = new_node();
read_node(new);
if(first == NULL)
{
new->link = NULL;
}
if(new->data <= first->data)
{
new->link = first;
}
ptemp = first;
while(ptemp->link != NULL && strcmp(ptemp->link->data, new->data) < 0)
{
ptemp = ptemp->link;
}
new->link = ptemp->link;
ptemp->link = new;
first = new;
}
how is it now? :) sorry i suddenly disappeared from here, i went to the bar and each time i thought about this algorithm the more thirsty i got so...it didnt end well :P
lol. Well, I hope you have a fresh head now ;)
Ok, we're getting closer, but there's still some work to do.
You've correctly identified 3 cases :
(a) the linked list is empty, so we want the new node to be the first (and only) node in the linked list :
>> if(first == NULL)
>> {
>> new->link = NULL;
>> }
This is good, but you still need to let 'first' point to the new node.
(b) the linked list is not empty, but the new node has to be inserted before the first node :
>> if(new->data <= first->data)
>> {
>> new->link = first;
>> }
This is good, but again, you still need to let 'first' point to the new node.
(c) the linked list is not empty, and the new node has to be inserted somewhere in the middle of the list :
>> ptemp = first;
>> while(ptemp->link != NULL && strcmp(ptemp->link->data, new->data) < 0)
>> {
>> ptemp = ptemp->link;
>> }
>> new->link = ptemp->link;
>> ptemp->link = new;
This is good. The new node is inserted where it should. Nothing more needs to be done. In particular, the line you put after this code is not supposed to be there :
>> first = new;
AND, another very important remark : the three cases you have identified need to be kept separate ! You can only execute one of the three pieces of code above, not all three. So, you'll need to have a bit of code like this :
Business Accounts
Answer for Membership
by: Infinity08Posted on 2009-11-20 at 10:22:06ID: 25872963
for information, this is a follow-up of http://www.experts-exchang e.com/Prog ramming/La nguages/C/ Q_24917520 .html
>> but now i have a new question on ordered insertion on a ordered list.
And what's the question ?