how do I enter a value v in a list of increasing order in the correct position, in linked list ?
Using the formulations of the list I got, but linked list not
linked list
Started by Apprentice123, Sep 09 2009 11:41 AM
13 replies to this topic
#1
Posted 09 September 2009 - 11:41 AM
|
|
|
#2
Posted 09 September 2009 - 12:17 PM
It will depend on the details of your linked list implementation.
#3
Posted 09 September 2009 - 12:26 PM
WingedPanther said:
It will depend on the details of your linked list implementation.
The type node is:
node = ref (
info: element "element of a node"
next: list "successor of the node or the rest of the list"
);
Example function cons: "Produces a list where v is the first element"
Algorithm:
func cons(v: element, L: list) return list; var aux: ref node; begin allocate(aux); aux^.info := v; aux^.next := L; return aux end; end.
#4
Posted 09 September 2009 - 01:20 PM
you understand the type node?
#5
Posted 09 September 2009 - 01:26 PM
I do not know how:
Linked list
1) Enter a value in a certain position
2) remove an element from the beginning without eliminating
3)
Linked list
1) Enter a value in a certain position
2) remove an element from the beginning without eliminating
3)
#6
Posted 09 September 2009 - 01:26 PM
Generally, you have to scan through your list node by node until you find the correct position. Then you create a new node and update pointers.
before: "x" --> "z" after: "x" --> "y" --> "z"
#7
Posted 09 September 2009 - 01:31 PM
WingedPanther said:
Generally, you have to scan through your list node by node until you find the correct position. Then you create a new node and update pointers.
before: "x" --> "z" after: "x" --> "y" --> "z"
1) Suppose the list L in ascending order inserts the value v in its rightful place
ins_ord(L: list, v: value) return value;
How can I browse through the list, linked list, to find a value greater than v, to insert v before the value?
#8
Posted 09 September 2009 - 01:51 PM
You need a pointer to step through your list. if temp.next.info < "y" then temp=temp.next.
#9
Posted 09 September 2009 - 02:08 PM
WingedPanther said:
You need a pointer to step through your list. if temp.next.info < "y" then temp=temp.next.
Please look:
It is ?
func ins_ord(L: list, v: value) return value; var temp: ref node; begin if temp^.info < v then temp^.prox = v; else L^.prox = v; end;
#10
Posted 10 September 2009 - 07:46 AM
That doesn't look right. BTW, what language is this?
These C++ tutorials may help:
http://forum.codecal...sing-lists.html
http://forum.codecal...nked-lists.html
These C++ tutorials may help:
http://forum.codecal...sing-lists.html
http://forum.codecal...nked-lists.html
#11
Posted 12 September 2009 - 07:54 AM
WingedPanther said:
That doesn't look right. BTW, what language is this?
These C++ tutorials may help:
http://forum.codecal...sing-lists.html
http://forum.codecal...nked-lists.html
These C++ tutorials may help:
http://forum.codecal...sing-lists.html
http://forum.codecal...nked-lists.html
Not the language, is only an algorithm
#12
Posted 12 September 2009 - 01:23 PM
I know, but there are a LOT of algorithms you can pull out of the tutorials.


Sign In
Create Account


Back to top









