Question

Data Structures and Algorithms (Java Programming) a) When devising an algorithm for linked lists, why must...

Data Structures and Algorithms (Java Programming)

a) When devising an algorithm for linked lists, why must you be careful about the order in which you change the references?

b) What code would be needed to change the references in a linked list when moving up one node?

c) Why did we have a previous reference in our linked list implementation?

d) Write a class for a linked list node with just one constructor that allows the initialization of all instance variables.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.While devising an algorithm for linked lists, we be careful about the order in which you change the references.Because those references are used to traverse the linked lit.if the references were not perfectly assigned the linked list wont work properly..

hence we have to be careful about reference assigning in linked list.

2.The moving up should be done in linked list the current element has a next element i.e next!=NULL

hence the code is...

node *start=head of the tail;

while(start!=NULL)

{

//now start is a node.......can do your operations..

System.out.println("NODE ::"+start.data);

//moving up one node

start=start.next;

}

3.The previous reference in the linked ist node i used when we are removing a node from the inked list....

when removing a node,we have to change the previous node of the current node point so that its next reference points to the next reference of the current node.....

i.e. NULL<--A-><-B-><-C->NULL

while deleting B....

NULL<--A-><-C->NULL

hence the previous reference is needed to delete a node successfully....

4.

1.class Node
2.{
3. public int data;
4. public Node next, prev;
5. public Node(int d, Node n, Node p)
6. {
7. data = d;
8. next = n;
9. prev = p;

10.   }

11 .}

Add a comment
Know the answer?
Add Answer to:
Data Structures and Algorithms (Java Programming) a) When devising an algorithm for linked lists, why must...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Data Structures and Algorithms (Java Programming) a) When devising an algorithm for linked lists, why must...

    Data Structures and Algorithms (Java Programming) a) When devising an algorithm for linked lists, why must you be careful about the order in which you change the references? b) What code would be needed to change the references in a linked list when moving up one node? c) Why did we have a previous reference in our linked list implementation? d) Write a class for a linked list node with just one constructor that allows the initialization of all instance...

  • Data Structures and Algorithms (Java Programming) Write a method to search for and remove an element...

    Data Structures and Algorithms (Java Programming) Write a method to search for and remove an element from a linked list, thereby returning the data portion of the node.

  • Data Structures & Algorithms If we were to implement the list as a circular linked list...

    Data Structures & Algorithms If we were to implement the list as a circular linked list (CLL) with a header node, how would this adjustment affect our ability to traverse the list? What advantage(s) would the adjusted list have over the current one?

  • Programming Assignment 1 Data structure Java Implement Shellsort for a linked list, based on a variant...

    Programming Assignment 1 Data structure Java Implement Shellsort for a linked list, based on a variant of bubble sort. The rather severe constraints imposed by the singly-linked list organization presents special problems for implementing Shellsort. Your task is to overcome these constraints and develop a simple, elegant implementation that does not sacrifice efficiency or waste space. Step 1. First, implement a routine to build a list: read integers from standard input, and build a list node for each item consisting...

  • // Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. //...

    // Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. // the variable: back "points" at the first node in the linked list // new elements ( enqueued) are added at the back // the variable: front "points" at the last node in the linked list. // elements are removed (dequeued) from the front // // Several queue instance methods are provided for you; do not change these // Other instance methods are left for...

  • List of Candles Create a class called CandleNode which has fields for the data (a Candle)...

    List of Candles Create a class called CandleNode which has fields for the data (a Candle) and next (CandleNode) instance variables. Include a one-argument constructor which takes a Candle as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures”.) public CandleNode (Candle c) { . . } The instance variables should have protected access. There will not be any get and set methods for the two instance variables. Create an abstract linked list class called CandleList. This...

  • Create a class called CarNode which has fields for the data (a Car) and next (CarNode)...

    Create a class called CarNode which has fields for the data (a Car) and next (CarNode) instance variables. Include a one-argument constructor which takes a Car as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures”.) public CarNode (Car c) { . . } The instance variables should have protected access. There will not be any get and set methods for the two instance variables. Create an abstract linked list class called CarList. This should be a...

  • C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use...

    C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use to implement your program can have a profound impact on it's overall performance. A poorly written program will often need much more RAM and CPU time then a well-written implementation. One of the most basic data structure questions revolves around the difference between an array and a linked list. After you finish this assignment you should have a firm understanding of their operation. Problem...

  • CSBP 319 Data structures - Linked Lists - USE JAVA (NetBeans) A company would like to...

    CSBP 319 Data structures - Linked Lists - USE JAVA (NetBeans) A company would like to implement its inventory of computing machines as a linked list, called ComputerList. Write a Computer node class, called ComputerNode, to hold the following information about a Computer: • code (as a String) • brand (as a String) • model (as a String) • price (as double) • quantity (as int) ComputerNode should have constructors and methods (getters, setters, and toString()) to manage the above...

  • Assignment: Chapter 18 introduces you to linked lists. In this homework assignment you will use the...

    Assignment: Chapter 18 introduces you to linked lists. In this homework assignment you will use the algorithms presented in this chapter to implement a list of names that should be kept in alphabetical order. Section 18.2 defines the Linked List Operations based on a list of numbers. You will change this code to work with a list of names. struct ListNode { string firstNname; string lastName; struct ListNode *next; }; Rename class NumberList to something more appropriate like StringList or...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT