Insertion to a sorted list

C

chai

I am trying out a program to insert an element to a sorted list(singly
linked list)without using the temporary variable.Is there a solution
for this problem?
 
A

Alexei A. Frounze

chai said:
I am trying out a program to insert an element to a sorted list(singly
linked list)without using the temporary variable.Is there a solution
for this problem?

This group deals with standard C, not algorithms. If you have an algorithm
but have problems expressing it's in terms of C (your code isn't compiling
or working as per the algorithm), come here for the help. But if you need
the algorithm, this isn't the right group to ask for it.

Alex
 
M

Mabden

chai said:
I am trying out a program to insert an element to a sorted list(singly
linked list)without using the temporary variable.Is there a solution
for this problem?

Not a problem. No temporary variable is required. What did your teacher
say to make you think there was one? Maybe you could stay after class
and ask, or make a friend who can help.
 
D

Dale

chai said:
I am trying out a program to insert an element to a sorted list(singly
linked list)without using the temporary variable.Is there a solution
for this problem?

I presume you mean you don't want to walk a pointer down the list looking
for the correct spot to insert.

One way would be to write a recursive insert function. Call it with a
pointer to the list, and have it call itself with the pointer to the next
node in the list until it finds the insertion point. (Not gonna write the
code for you, junior. But it ain't that hard.)

That would be a fucking stupid way to do it, though. A temporary pointer
requires a lot less memory and fewer CPU cycles.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top