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 & 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?

  • // 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...

  • 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...

  • On Java: Problems Problem 1. (Deque) Hints: my Use a doubly-linked list Node to implement the...

    On Java: Problems Problem 1. (Deque) Hints: my Use a doubly-linked list Node to implement the API — each node in the list stores a generic item, and references next and prev to the next and previous nodes in the list null itemi → item2 item3 ... itemn null Instance variables wy Reference to the front of the deque, Node first my Reference to the back of the deque, Node last my Size of the deque, int n + LinkedDeque...

  • Summer II 2020 - Data Structures and Algorithms (COSC-2336-01W) In the linked-list based bag implementation, we...

    Summer II 2020 - Data Structures and Algorithms (COSC-2336-01W) In the linked-list based bag implementation, we demonstrated the functionalities, such as, add, remove, and list. This assignment is to extend the functionalities of the bag with other operations average, min, and max, You need to extend the Bag class (under Wk 2, BagLinked_List.cpp) with the following methods: -int Bag::min( ), is to find minimum of items of the bag. -int Bag::max( ), is to find maximum of items of the...

  • SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what...

    SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what choices does one make when creating a class that is an example of Abstraction? Encapsulation: What is encapsulation? What is information hiding? What does a public interface to a class consist of (not in the sense of actual java interfaces but what the client uses to manipulate objects of the class) What is an object of a class? What is the constructor? How do...

  • PLEASE WRITE IN JAVA AND ADD COMMENTS TO EXPLAIN write a class NameCard.java which has •Data...

    PLEASE WRITE IN JAVA AND ADD COMMENTS TO EXPLAIN write a class NameCard.java which has •Data fields: name (String), age(int), company(String) •Methods: •Public String getName(); •Public int getAge(); •Public String getCom(); •Public void setName(String n); •Public void setAge(int a); •Public void setCom(String c); •toString(): \\ can be used to output information on this name card 2, write a class DoublyNameCardList.java, which is a doubly linked list and each node of the list a name card. In the DoublyNameCardList.java: •Data field:...

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
ADVERTISEMENT