Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a preference for the code to be in Java if possible. Q1 - 25 pts) The del

ID: 3871097 • Letter: I

Question

I have a preference for the code to be in Java if possible.



Q1 - 25 pts) The deleteElement int deleteData) member function in the code for the Singly Linked List based implementation of a List ADT deletes the first occurrence of deleteData in the List. Modify this member function in such a way that all occurrences of deleteData in the List are deleted with a single call to the deleteElement function from main. After you modify the deleteElement function, run the main function (as given in the startup code for this question) by creating a List of at least 10 elements with certain elements repeating. Now ask for a value (delete Data) to delete from the user and call thoe deleteElement deleteData) function to delete all occurrences of deleteData in the List. Capture the output of your program displaying the contents of the List before and after the call to the deleteElement function A sample of the expected screenshot of the program is shown below. As noticed in the screenshot, all occurrences of deleteData '15' in the List are removed after a call to the deleteElement function. Enter he nusher of elenenso you want to insert: 18 Enter eier ent 12 Enter element 1 : 14 Enter element 2 14 Enter eier ent : 15 Enter Enter Enter ele" ent ele-ent ele-ons 6 : 17 7 15 : 19 Contente of the List: Chefore delete 12 14 14 15 15 18 17 15 19 14 Enter the data to delete: 15 Contente of the List Cafter delete 12 14 14 18 17 19 14 Q2-25 pts) The Fibonacci sequence is generated using the following recursion: F(n) = F(n-2) + F(n-1), for n > 1,F(0) = 0 and F( 1 ) = 1 In this question, you will generate the Fibonacci sequence as a "Singly Linked List" of integers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, N where N is the largest integer in the sequence that is less than the integer J comprising the last three digits of your For example, if your J# is J00543244, then J is 244 . In that case, the Fibonacci sequence that is generated should be 0,, 2, 3.5, 8, 13, 21, 34. 55, 89, 144, 233. If the last three digits of your J# form an integer that is less than 100, add 100 to the last three digits of your J# and use the resulting value as J. For example, if your J# is J00543034, then J is 34 + 100 = 134 and the Fibonacci sequence generated would be: 0, 1. 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 You are given the code for the Singly Linked List-based implementation of the List ADT. Add a member function constructSequence int) to the List class that takes an integer argument (upperBound: J for the Fibonacci sequence) The main function given to you already inserts the first two nodes (with data 0 and 1 respectively) to a List called FibonacciList. Your task will be to implement the constructSequence function that will insert a sequence of nodes (one node per iteration) to the FibonacciList whose last elemen l be the largest element in the t uence that is less than the upperBounad Q3 -20 pts) You are given the code (including the main function) for evaluating an expression in post-fix format using Stack. Your task is to modify the code in the main function to input an expression in pre-fix

Explanation / Answer

Q1:-

// A complete working Java program to demonstrate deletion in singly

// linked list

import java.util.Scanner;  

class LinkedList

{

Node head; // head of list

/* Linked list Node*/

class Node

{

int data;

Node next;

Node(int d)

{

data = d;

next = null;

}

}

/* Given a key, deletes the all occurrence of key in linked list */

void deleteNode(int key)

{

// Store head node

Node temp = head, prev = null;

// If head node itself holds the key to be deleted

if (temp != null && temp.data == key)

{

head = temp.next; // Changed head

// recursively call delete again to delete all other occurance

deleteNode(key);

return;

}

// Search for the key to be deleted, keep track of the

// previous node as we need to change temp.next

while (temp != null && temp.data != key)

{

prev = temp;

temp = temp.next;

}

// If key was not present in linked list

if (temp == null) return;

// Unlink the node from linked list

prev.next = temp.next;

// recursively call delete again to delete all other occurance

deleteNode(key);

}

/* Inserts a new Node at front of the list. */

public void push(int new_data)

{

Node new_node = new Node(new_data);

new_node.next = head;

head = new_node;

}

/* This function prints contents of linked list starting from

the given node */

public void printList()

{

Node tnode = head;

while (tnode != null)

{

System.out.print(tnode.data+" ");

tnode = tnode.next;

}

System.out.println("");

}

/* Drier program to test above functions. Ideally this function

should be in a separate user class. It is kept here to keep

code compact */

public static void main(String[] args)

{

LinkedList llist = new LinkedList();

Scanner sc=new Scanner(System.in);

System.out.print("Enter the number of elements you want to insert : ");

int N;

N = sc.nextInt();

System.out.println(String.valueOf(N));

for(int i = 0 ; i < N; i++){

int M;

System.out.print("Enter element at " + i + " : ");

M = sc.nextInt();

llist.push(M);

System.out.println(String.valueOf(M));

}

System.out.println(" Content of list ( before delete )");

llist.printList();

System.out.print("Enter the number you want to delete : ");

int D;

D = sc.nextInt();

System.out.println(String.valueOf(D));

llist.deleteNode(D); // Delete node at position 4

System.out.println(" Content of list ( after delete ) :");

llist.printList();

}

}

INPUT:-

10
12
14
14
15
15
18
17
15
19
14
15

Output:-

Enter the number of elements you want to insert : 10
Enter element at 0 : 12
Enter element at 1 : 14
Enter element at 2 : 14
Enter element at 3 : 15
Enter element at 4 : 15
Enter element at 5 : 18
Enter element at 6 : 17
Enter element at 7 : 15
Enter element at 8 : 19
Enter element at 9 : 14

Content of list ( before delete )
14 19 15 17 18 15 15 14 14 12
Enter the number you want to delete : 15

Content of list ( after delete ) :
14 19 17 18 14 14 12