473,769 Members | 1,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doubly-Link List?

I wrote the following code to create a short doubly-link list of three
strings: "one", "two", and "three". I would like to know if I set them up
correctly, so that they point to one another.

DLLNode class has already been created. Basically, "one" is the head node,
"two" is the mid node, and "three" is the tail or the last node. I would
like to know if my algorithm for setting up doubly-linked node are correct
before I proceed to printing them. Can anybody give me comments regarding
my algorithm?

public class TestNode
{
private static DLLNode head = null;
private static DLLNode tail = null;
private static DLLNode index = null;

public static void main(String[] args)
{
DLLNode node = new DLLNode("One", null, head);
if (head == null) //list empty
{
head = tail = index = node;
return;
}
head.setPrev(no de);
head = node;

DLLNode node1 = new DLLNode ("Two");
index.setNext(n ode1);
index.setPrev(h ead);
index = node1;

DLLNode node2 = new DLLNode("Three" , tail, null);
tail.setNext(no de2);
tail.setPrev(no de1);
tail = node2;

}
}
Jul 17 '05 #1
1 2217
Liz
I hate to bring this up, but did you try it?
If you are going to use it you are going to have to try it eventually.
Also, you should expect that you should be doing some testing of your code
too.
After all, how many bosses would put up with "I wrote the code and some
geek on usenet said it works for him ok, so it must be right."

"D. Beckham" <le*******@eart hlink.net> wrote in message
news:vv******** **********@news read1.news.pas. earthlink.net.. .
I wrote the following code to create a short doubly-link list of three
strings: "one", "two", and "three". I would like to know if I set them up
correctly, so that they point to one another.

DLLNode class has already been created. Basically, "one" is the head node,
"two" is the mid node, and "three" is the tail or the last node. I would
like to know if my algorithm for setting up doubly-linked node are correct
before I proceed to printing them. Can anybody give me comments regarding
my algorithm?

public class TestNode
{
private static DLLNode head = null;
private static DLLNode tail = null;
private static DLLNode index = null;

public static void main(String[] args)
{
DLLNode node = new DLLNode("One", null, head);
if (head == null) //list empty
{
head = tail = index = node;
return;
}
head.setPrev(no de);
head = node;

DLLNode node1 = new DLLNode ("Two");
index.setNext(n ode1);
index.setPrev(h ead);
index = node1;

DLLNode node2 = new DLLNode("Three" , tail, null);
tail.setNext(no de2);
tail.setPrev(no de1);
tail = node2;

}
}

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
12484
by: Marc Ferry | last post by:
I already posted this mail in comp.sys.hp and comp.sys.hp.hpux but had no response. As this problem might be present on other OSes than HP-UX 10.20, I crosspost it here, in the hope of getting an answer. ************************* In C/C++ system include files on HP-UX 10.20, /usr/include/values.h defines macro MAXINT as (~HIBITI) /usr/include/sys/param.h defines macro MAXINT as 0x7fffffff
12
2709
by: DrBonzo | last post by:
Given public class A { virtual void foo() { ... } } public class B : A { public override void foo() { ... } public Bthingy() { ... base.foo() ...} }
8
3947
by: tonywinslow1986 | last post by:
I'm reading MIT's book "Introduction to Algorithms". The following is one of the excercises from it: < 10.2-8 Explain how to implement doubly linked lists using only one pointer value np per item instead of the usual two (next and prev). Assume that all pointer values can be interpreted as k-bit integers, and define np to be np = next XOR prev, the k-bit "exclusive-or" of next and prev. (The value NIL is represented by
4
2032
by: paeez | last post by:
how can i add a node after ith node in a doubly linkedlist?(for example after the third node)
2
2095
by: zubia | last post by:
hi how 2 deal with the rptr n lptr in doubly linklist
0
9579
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9420
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10205
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9984
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.