Questions
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly...

Exercise 1:
Write a program in Java to manipulate a Singly Linked List:

1. Create Singly Linked List
2. Display the list
3. Count the number of nodes
4. Insert a new node at the beginning of a Singly Linked List.
5. Insert a new node at the end of a Singly Linked List
6. Insert a new node after the value 5 of Singly Linked List
7. Delete the node with value 6.
8. Search an existing element in a Singly linked list (the element of search is given by the user)
9. Call all methods above in main method with the following data:

Test Data :
Input the number of nodes : 3
Input data for node 1 : 2
Input data for node 2 : 5
Input data for node 3 : 8

In: Computer Science

C++ 1. The function removeAt of the class arrayListType removes an element from the list by...

C++
1. The function removeAt of the class arrayListType removes an element from the list by shifting the elements ofthe list. However, if the element to be removed is at the beginning ofthe list and the list is fairly large, it could take a lot ofcomputer time. Because the list elements are in no particular order, you could simply remove the element by swapping the last element ofthe list with the item to be removed and reducing the length of the list. Rewrite the definition of the function removeAt using this technique.
2. The function remove of the class arrayListType removes only the first occurrence of an element. Add the function removeAll to the class arrayListType that would remove all occurrences of a given element. Also, write the definition ofthe function removeAll and a program to test this function.

From the textbook Data Structures using C++ by D. S. Malik

In: Computer Science

Write a Python program using functions and mainline logic which prompts the user to enter a...

Write a Python program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a file. It should then display the following data to back to the user:

  • The list of integers
  • The lowest number in the list
  • The highest number in the list
  • The total sum of all the numbers in the list
  • The average number in the list
  • At a minimum, the numbers should range from 0 to 50, but you can use any range you like.

In: Computer Science

In c++ please. Write a program that reads the contents of two text files and compares...

In c++ please.

Write a program that reads the contents of two text files and compares them in the following ways:

It should display a list of all the unique words contained in both files.

It should display a list of the words that appears in both files.

It should display a list of the words that appears in the first file, but not the second.

It should display a list of the words that appears in the second file, but not the first.

It should display a list of the words that appears in either the first or second file, but not both.

In: Computer Science

A company would like to implement its inventory of smartphones as a doubly linked list, called...

A company would like to implement its inventory of smartphones as a doubly linked list, called

MobileList.

1. Write a Mobile node node class, called MobileNode, to hold the following information about a

smartphone:

• code (as a String)

• brand (as a String)

• model (as a String)

• price (as int)

MobileNode should have constructors and methods (getters, setters, and toString()) to manage

the above information as well as the link to next and previous nodes in the list.

2. Write the MobileList class to hold objects of the class MobileNode. This class should define:

• Two instance variables first and last to keep the reference (address) of the first and last

nodes of the list.

• The MobileList class should implement the following interface:

public interface MList {

public boolean isEmpty();

// returns true if the list is empty, false otherwise

public int size();

// returns the number of items in the list

public MobileNode getNodeAt(int index);

//returns the MobileNode object at the specified index

public void addFirst(MobileNode item);

// adds a Mobile node at the front of the list

public void addLast(MobileNode item);

// adds a Mobile node at the end of the list

public void addAt(int index, MobileNode item);

// adds a Mobile node to the list at the given index

public String removeAt(int index);

// removes the Mobile node from the list that has the given

// index

public String remove(MobileNode item);

// removes the first item in the list whose data equals

// the given item data

public MobileNode[] searchPriceGreaterThan(int p);

//search and return an array of the set of MobileNode items

//having a price greater than p

public double averagePrice();

// return the average price of the mobile nodes in the list

public double averageBrandPrice(String brand);

// return the average price of the mobile nodes in the list

// from the brand given as a parameter (e.g., “Samsung” or

// “samsung”)

@Override

public String toString();

// implement a toString() method that prints the list in the

// format:

//[ size: the_size_of_the_list

// Mobile node1,

// Mobile node2,

//.... ]

}

3. Write a TestMobileList class to test the class MobileList. This class should have a main method

in which you perform the following actions:

• Create a MobileList object,

• Insert 10 MobileNode objects into the created list (from some brands like “Apple”,

“Samsung”, “Huwaei”, “Sony”),

• Print the content of your list,

• Find out in the list the items that have a price greater than 3000. Print them out.

• Remove the first element of the list

• Remove the item at index 3

• Print again the content of your ist,

• Print out the average price of all mobiles in the list

• Print out the average price of all mobiles in the list from “Apple”.

For each operation above, print a small message that describes the operation you are doing.

For example:

System.out.println(“Insertion of 10 Mobile nodes in the list”);

In: Computer Science

Python 3 Function which takes the head Node of a linked list and sorts the list...

Python 3 Function which takes the head Node of a linked list and sorts the list into non-descending order. PARAM: head_node The head of the linked list RETURNS: The node at the head of the sorted linked list. '''

def sort(head_node):

#Code goes here

''' Test code goes here ''

' if __name__ == '__main__':

In: Computer Science

how do i find a peak in time complexity of O(log(n)) in a list? input: a...

how do i find a peak in time complexity of O(log(n)) in a list?

input: a list of numbers or integers

output: a possible local peak in the list

for an example:

calling function [2,3,8,9,5] would return 3

im thinking about using binary search but it would require a sorted list.

In: Computer Science

I need to implement a method that removes any duplicate items in a list and returns...

I need to implement a method that removes any duplicate items in a list and returns the new values   

private static linkedlist removeDuplicates(linkedlist list)
{

   return list;
}

In: Computer Science

Write the Java source code necessary to build a solution for the problem below: Create a...

Write the Java source code necessary to build a solution for the problem below:
Create a MyLinkedList class. Create methods in the class to add an item to the head, tail, or middle of a linked list; remove an item from the head, tail, or middle of a linked list; check the size of the list; and search for an element in the list.

Create a test class to use the newly created MyLinkedList class. Add the following names in to the list: James, John, Michael, Peter, Allison, Daniel, George, Simon, Jason, and Mark. Your program should allow the user to enter a name from the console, and then search to see if the name exists in the list.

In: Computer Science

Using the following list and a “for” loop, display differences of all consecutive pairs of numbers...

Using the following list and a “for” loop, display differences of all consecutive pairs of numbers in the list. our_list = [1,2,5,6,3,77,9,0,3,23,0.4,-12.4,-3.12] The output should look like this: 1 3 1 … 4.

Using a “while loop” ask the user for a number and add it to a list if number is even and to a different list if number is odd. Keep asking the user for a number until he says “I’m bored” and doesn't want to give you any more numbers.

5. For the following list, print each element in the list an it’s type. list5 = ['a','b',1,2,[1,2,3,4],'hello',(4,5,6),7,True,"False",2.3]

In: Computer Science