Now modify the add method of DoubleLinkedSet so that it properly links the nodes in both directions
I have to modify the add method of my doublelinked set so that it links nodes in both directions. here is part of the code. -
-
public void add (T element)
-
{
-
if (!(contains(element)))
-
{
-
DoubleNode<T> node = new DoubleNode<T> (element);
-
node.setNext(contents);
-
contents = node;
-
count++;
-
}
-
}
Now I tired to change it up and add a .setPrevious too but it did not work. Basically I have no idea what to do Any help would be greatful
8 1961
Your DoubleNode class should have a setPrevious function to have a link to the previous data...I think we need to see a little more code for this problem.
Here is the rest of the whole code. I tried putting a setPrevious in there but whenever I tried it, it didnt put the numbers before and after the add.
From what I understand, your list should have 2 DoubleNodes - one for the front end of the list, and one for the back. Was this data structure given to you, or did you make it yourself?
It was given. I tried this: - public void add (T element)
-
{
-
if (!(contains(element)))
-
{
-
DoubleNode<T> node = new DoubleNode<T> (element);
-
node.setNext(contents);
-
contents = node;
-
count++;
-
node.setPrevious(contents)
-
contents=node;
-
count++;
-
-
-
}
-
}
Still no go for that.
Well, you wouldn't be incrementing count again - after all, you're only adding one node. What you'll have to do is use current's previous node to set the new node's previous.
How would you modify the remove method so that they take advantage of the doubly-linked structure. Why would you eliminate the variable previous?
I'm sorry, I don't quite understand your question...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dan Weeb |
last post by:
Hi All,
I have struggled through this far with help from many of you so thanks. I am
stuck again. I am really new to this so don't be harsh :-)
There are a few problems. You can run the script...
|
by: nospam |
last post by:
Amazon wins patent for ordering forms, Collapsing and Maximizing Form
Areas....
NAME OF PATENT
Method and system for displaying and editing of information
# 6,615,226 ...
|
by: Sam |
last post by:
I'm having problem. I want to have a block of code run, after a user edits the label of a node, so I put the code in the event method of the afterLabelEdit event. The problem is that this code is...
|
by: Marc Scheuner [MVP ADSI] |
last post by:
Folks,
I'm trying to get a grip on customizing my WebBrowser control hosted
on a WinForms form.
I've come as far as finding out about IDocHostUIHandler, and I've
implemented the...
|
by: Ron Weldy |
last post by:
I have a test server runinng 2003/IIS 6 with a mixture of asp and asp.net
files. On my workstation I have a share set up to the folder where the web
files reside. I am just doing quick and dirty...
|
by: Nathan Sokalski |
last post by:
I have a DataList control with an EditTemplate. Three of the controls in
this template include a Calendar, a Button with CommandName="update", and a
Button with CommandName="cancel". Whenever I...
|
by: Vanga Sasidhar |
last post by:
Hi All,
Please help me in the following problem.
I am having some files with AVI extension. I want to make two programs in
Visual Basic .NET which will work with these AVI Files. One program...
|
by: Ian Bicking |
last post by:
I got a puzzler for y'all. I want to allow the editing of functions
in-place. I won't go into the reason (it's for HTConsole --
http://blog.ianbicking.org/introducing-htconsole.html), except that...
|
by: ritesh |
last post by:
Hi,
I'm facing a problem in which I need to edit an already created file,
and the editing needs to be done at the start of the file rather then
appending to the file.
OS - Linux,Solaris
...
|
by: cpnet |
last post by:
I have a GridView which I'm populating from an ObjectDataSource (give the
GridView a DataTable). The GridView will have about 20 rows, and only one
editable column. The editable column consists...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |