So I will try to sum my problem up, if it is not clear, please tell me:
So I have an array of char contain a number. So let say I have a string that is 56789.
I change that string to array of char. I want to put it in a a doubly linked list, with head contain 5 and tail contain 9, everything in between.
Node class just has 3 fields which are char data, prev and next.
I am not sure how to put the value in the list using a for loop, since I know the size of the number. But now I think this way. First I would make a singly linked list, and setNext forward, then start again from tail to setPrev, then put the values in the list last.
Are there other ways to do this? Thank guys in advance.
Methods to create an empty doubly linked list.
Page 1 of 16 Replies - 148 Views - Last Post: 09 March 2013 - 03:02 PM
Replies To: Methods to create an empty doubly linked list.
#2
Re: Methods to create an empty doubly linked list.
Posted 09 March 2013 - 01:43 AM
Show the code for your doubly linked list.
#3
Re: Methods to create an empty doubly linked list.
Posted 09 March 2013 - 02:37 PM
Oh Greg, I have not encounter any bugs or so, just simply asking on what other alternative exist besides what I said.
#4
Re: Methods to create an empty doubly linked list.
Posted 09 March 2013 - 02:45 PM
I'm still confused by your thought of starting with a singly-linked list, that's why I asked to see your code.
No, you wouldn't start with one kind of a linked list and change it to another. And for a linked list, single- or double-, there can be methods that add a new node to the end, to the beginning, in sorted order, or inserted randomly somewhere between the head and the tail.
Seeing your list code and the methods you'd written to add nodes would have clarified your question about adding new nodes.
No, you wouldn't start with one kind of a linked list and change it to another. And for a linked list, single- or double-, there can be methods that add a new node to the end, to the beginning, in sorted order, or inserted randomly somewhere between the head and the tail.
Seeing your list code and the methods you'd written to add nodes would have clarified your question about adding new nodes.
#5
Re: Methods to create an empty doubly linked list.
Posted 09 March 2013 - 02:48 PM
If your lList has a method to append to it
it is quite easy to pass through the array appending a Node for each of the char
it is quite easy to pass through the array appending a Node for each of the char
#6
Re: Methods to create an empty doubly linked list.
Posted 09 March 2013 - 02:57 PM
GregBrannon, on 09 March 2013 - 02:45 PM, said:
I'm still confused by your thought of starting with a singly-linked list, that's why I asked to see your code.
No, you wouldn't start with one kind of a linked list and change it to another. And for a linked list, single- or double-, there can be methods that add a new node to the end, to the beginning, in sorted order, or inserted randomly somewhere between the head and the tail.
Seeing your list code and the methods you'd written to add nodes would have clarified your question about adding new nodes.
No, you wouldn't start with one kind of a linked list and change it to another. And for a linked list, single- or double-, there can be methods that add a new node to the end, to the beginning, in sorted order, or inserted randomly somewhere between the head and the tail.
Seeing your list code and the methods you'd written to add nodes would have clarified your question about adding new nodes.
My mind 's a mess recently so I kind of forget on how to insert node in a dlinked list. What I said above means insert node into the list and establish the connection between nodes with the next field first, then traverse the node again, and connect the nodes with the prev field. But scratch that, I thinking weird stuffs. When I get back on my comp, def upload the code.
#7
Re: Methods to create an empty doubly linked list.
Posted 09 March 2013 - 03:02 PM
Sure that the appendNode() method of a SingleList has the responsabilty to update the forward and backward pointers of the nodes involved in the operation mainly the firt/last node and the new inserted node.
You can implement 2 different versions (or even borth versions) of the insertNode() method. One that receives a Node as parameter and a one that receive the data as parameter. In that case the method creates the node and then call the previous one.
You can implement 2 different versions (or even borth versions) of the insertNode() method. One that receives a Node as parameter and a one that receive the data as parameter. In that case the method creates the node and then call the previous one.
This post has been edited by pbl: 09 March 2013 - 04:30 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|