how can i implement a polynomial class using the doubly linked list data structure such that each node of the list holds the coeffient and the exponent of the term ?

Recommended Answers

All 11 Replies

Define a Node class with the required variables.

If you are having problems with your code, post it and ask some specific questions.

         public void extract(Object obj)
//       {
//           Element element = head;
//           while ((element != null) && (!element.data.equals(obj)))
//           {
//               element = element.next;
//           }
//
//           if (element == null)
//           {
//               throw new IllegalArgumentException("item not found");
//           }
//           if (element == head)
//           {
//               head = element.next;
//               if (element.next != null)
//               {
//                   element.next.previous = null;
//               }
//           }
//           else
//           {
//               element.previous.next = element.next;
//               if (element.next != null)
//               {
//                   element.next.previous = element.previous;
//               }
//           }
//           if (element == tail)
//           {
//               tail = element.previous;
//           }
//       }
`

this is the first time i work with doubly linked lists.
how is the element is delete if its found in the list? knowing that it is not a head or a tail ?
thanks in advanced

It best to use a piece of paper to draw out how the nodes in a linked list are connected
and to see how to remove a node from the list.

i did but couldnt understand how its working with the midle node.in head and tail i discovered how.at least give me a hint :D

Writing down a linked list on a piece of paper is the only way I know how to do it.
Draw lines that represent the links. When you remove a node, some of the lines must be redrawn.
When a line is redrawn that represents making a change to a node pointer.
Try making a list in pseudo code of how to remove a node in the three places: first, middle and last. There are several pointers that must be changed. If you know how to do the first and last, then only work on the middle node.

ok i will try again

Here are steps if the node is in the middle of the list (not head or tail).

1)Update the point-to next node of its previous node to its next node.
2)Update the point-to previous node of its next node to its previous node.

/*
Assuming nodeX0 is the head.
Removing nodeX4 from the list...

Start condition:
nodeX0 <-> ... <-> nodeX3 <-> nodeX4 <-> nodeX5 <-> ...

Apply #1
nodeX0 <-> ... <-> nodeX3 <- nodeX4 <-> nodeX5 <-> ...
                        |               ^
                        +---------------+

Apply #2
nodeX0 <-> ... <-> nodeX3 <- nodeX4 -> nodeX5 <-> ...
                      ^ |              ^ |
                      | +--------------+ |
                      +------------------+

Ignore the reference to nodeX4 and it will be removed from the memory by GC later on.
*/

Done... In Java, you don't need to manually free up memory or write a deconstructor.

hi . i need help.You are asked to implement a set of programs to simulate a group of users being logged onto a computer network. Users
may be added, deleted, modified, displayed and searched for at any time. A method to test whether a user’s name is a
palindrome (a string that reads the same from left to right as right to left) should also be included. Finally, a logout feature
should be added that continuously logs out users at random every three seconds. The users should be maintained within a
doubly linked list. You should modify the files supplied with this exercise to create a class for a circular doubly linked list,

Please start your own thread for your new problem.
Be sure to post the code you are working on and to ask specific questions about the problems you are having.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.