Question
Hello guys. Please help me asap! it's written in Java. thank you!! Method 1 public void deleteLetter(char c){ //your code here } This method deletes
Hello guys. Please help me asap! it's written in Java. thank you!!
Method 1
public void deleteLetter(char c){
//your code here
}
This method deletes all instances of the letter provided as the parameter from the doubly lined list. For example: myList.delete(n), all n characters will be deleted from the doubly linked list. In the example below, annex to would be reduced to aex. See Figure 1.
Figure1
Method 2
public void removeFirstLast(){
//your code here
}
This method removes the character(s) that are at the head and tail of the doubly linked list. For example: myList.removeFirstLast(), on a doubly linked list containing annex would reduce it to nne. See Figure2.
Figure2
Method 3
public void makePallindrome(){
//your code here
}
This method takes the existing letters in the doubly linked list and makes it a palindrome (using the tail as the pivot for the mirror image). For example: myList.makePallindrome(), on a doubly linked list containing aex would result in a doubly linked list that contains aexea. See Figure3.
Figure3
Method 4
public boolean letterPresent(char l){
//your code here
}
This method returns true if the char in the method parameter is present in the doubly linked list and false if it is not present. For example: myList.letterPresent(a) and myList.letterPresent(z) will return true and false respectively if called on a double linked list containing annex.
import java.util.*;
class Node { private char letter; private Node next, prev; public Node(char c) { letter = c; next = prev = null; } public char getLetter() { return letter; } public Node getNext() { return next; } public void setNext(Node n) { next = n; } public Node getPrev() { return prev; } public void setPrev(Node p) { prev = p; } }
public class L1Example { Node head, tail; public L1Example() { head = tail = null; }
// I added the return false because this function needs a boolean // that needs "call up " false. public boolean isPalindrome() { boolean isPalindrome = false; //your code here return false; } //////////////////////////////////////////////////////////////////////////////////// public void deleteLetter(char c) { Node temp = head;
while (temp != null) { if ( temp.getLetter() == c) { temp = temp.getNext(); temp.getPrev() = null; //this array needs to make small if the letters //remove } temp = temp.getNext(); } } public void removeFirstLast() { Node temp = head; temp = temp.getNext(); temp.getPrev() = null;
Node temp1 = tail; temp1 = temp1.getNext(); temp1.getPrev() = null;
System.out.print("delete: " + temp.c); return temp1.c; /* //this is a reference Node c = head;
//this method deletes the first node if (head == null) { return; }
if (head.getNext() == null) { head = null; return; }
head = head.getNext(); head.getPrev() = null;
// this method deletes the last node. while (c.getNext() != null) c = c.getNext(); c.getPrev.getNext() = null;*/ } public void makePallindrome() { //this is the function for head Node temp = head;
while (temp != null) { System.out.print(temp.getLetter()+ " "); temp = temp.getNext(); }
//this is the function for tail Node temp1 = tail;
while (temp1 != null) { System.out.print(temp1.getLetter()+ " "); temp1 = temp1.getNext(); }
} public boolean letterPresent(char l) { Node temp = head;
//this is scanning if the letters are true or false. while ( temp != null) { if (temp.getLetter() == l) return true; }
temp = temp.getNext();
return false; } //////////////////////////////////////////////////////////////////////////////////// public String concatinateBackward() { Node curr = tail; String backward=" "; while(curr!=null) { backward = backward+curr.getLetter(); curr = curr.getPrev(); } return backward; } public void firstBecomesLast() { } public void insert(char c) { Node nd = new Node(c); nd.setNext(head); if(head != null) head.setPrev(nd); else tail = nd; head = nd; } public void insert2(char c) {
} public static void main(String[] args) { L1Example myList = new L1Example(); myList.insert('a'); myList.insert('b'); myList.insert('c'); myList.insert('c'); myList.insert('d'); myList.insert('e'); System.out.println("The list read from tail to head:" +myList.concatinateBackward());
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started