Questions
Array-Based Linked List Implementation: JAVA Decide how to write the methods with items being stored in...

Array-Based Linked List Implementation: JAVA

Decide how to write the methods with items being stored in an array. NOT in linked List.
Implement an array-based Linked List in your language. Use double as the item. You need to create a driver includes several items and inserts them in order in a list.

Identify the necessary methods in a List Linked implementation. Look at previous Data Structures (stack or queue) and be sure to include all necessary methods.
DO NOT USE your language's Library List. You will receive zero points.
Write a LinkedList class:
class LinkList {
// attributes
// size
// maxSize
// array   
// CONSTRUCTORS
// METHODS   
// TOSTRING/DISPLAY--returns string }

Write a driver (tester) or write unit tests to test all your methods.
Test add methods
Test delete methods
Test size
Test print
Test adding to full list--handle exception
Test adding to empty list--handle exception

In: Computer Science

Below is for C language typedef struct _node { Node *next; char *str; } Node; You...

Below is for C language

typedef struct _node {

Node *next;

char *str;

} Node;

You are given a function that takes in two Node* pointers to two different linked lists. Each linked list node has a string represented by a character array that is properly null terminated. You're function is supposed to return true if the concatenation of strings in a linked list match each other, else return false.

EXAMPLES

List 1: "h" -> "el" -> "l" -> "o" -> NULL

List 2: "he" -> "llo" -> NULL

Return: True

List 1: "je" -> "lc -> "l" -> "o" -> NULL

List 2: "h" -> "e" -> "ll" -> "" -> "o" -> NULL

Return: False

List 1: “e” -> “llo” -> “h” -> NULL

List 2: “h” -> “e” -> “l” -> “l” -> “o” -> NULL

Return: False

bool areListsMatching(Node *list1, Node *list2) {

// TODO: Fill this

}

In: Computer Science

Below is for C language typedef struct _node { Node *next; char *str; } Node; You...

Below is for C language

typedef struct _node {

Node *next;

char *str;

} Node;

You are given a function that takes in two Node* pointers to two different linked lists. Each linked list node has a string represented by a character array that is properly null terminated. You're function is supposed to return true if the concatenation of strings in a linked list match each other, else return false.

EXAMPLES

List 1: "h" -> "el" -> "l" -> "o" -> NULL

List 2: "he" -> "llo" -> NULL

Return: True

List 1: "je" -> "lc -> "l" -> "o" -> NULL

List 2: "h" -> "e" -> "ll" -> "" -> "o" -> NULL

Return: False

List 1: “e” -> “llo” -> “h” -> NULL

List 2: “h” -> “e” -> “l” -> “l” -> “o” -> NULL

Return: False

bool areListsMatching(Node *list1, Node *list2) {

// TODO: Fill this

}

In: Computer Science

It's time to write a sorting algorithm! In this lab, you'll be writing Bubble Sort. Much...

It's time to write a sorting algorithm! In this lab, you'll be writing Bubble Sort. Much like the previous lab, you will be tasked with prompting the user for a list of values until the user enters 0 (you may use the same initializeVector that you wrote in the last lab). You will then write bubblesort which sorts the vector from smallest to largest. You will then call a function displayVector which displays the vector to the screen. Keep everything in this assignment. We will be using this to build selection sort. Instructions Create these functions (one of which you wrote in the last lab). void initializeVector(vector&); int bubblesort(vector&); void displayVector(vector&); void swap(vector&, int, int); Function Descriptions • initializeVector – This function prompt the user to add elements to the end of a vector until the user enters a 0. – The final 0 entered should not be added to the end of the vector. – Because the function passes the vector by reference, there's no need to return – Preconditions: none – Postconditions: the vector will be populated with values. – @param list the list to be populated with values. • bubblesort – This function will sort the values in the supplied list from smallest to largest. – It should also keep count of the number of times the swap function is called. – Precondition: none – Postcondition: the list will be sorted – @param list the list to be sorted – @return the number of swaps necessary to complete this sort • displayVector – This function will display the values of list. If the list is empty, it will instead say "The list is empty." – Precondition: none – Postcondition: none – @param list the list to be displayed • swap – This function will swap the values at two provided index locations in the provided vector and return nothing. – Precondition: both index locations are greater than or equal to 0 and less than the size of the vector. – Postcondition: The values of the vector at the two locations will be swapped. – @param list the list to have values swapped – @param first the first index to swap – @param second the second index to swap Instructions 1. Document the beginning of the program with your name, class number, section number, date, and description of the program. 2. Craft the functions. 3. Document those functions. 4. In the main, greet the user. For example, "Welcome to the Bubble Sort Number Sorter." 5. Create a vector of integers. 6. Call initializeVector using the vector of integers. 7. Call bubblesort using the vector of integers. 8. Display how many times it took to swap values. 9. Call displayVector to display the vector of integers. Examples Bubble Sort should handle an empty list with no special code. Welcome to the Bubble Sort Number Sorter. Enter values to add to list (Enter 0 to stop): 0 This sorting algorithm requried 0 swaps. Here are the values sorted. The list is empty. Bubble Sort should handle a list that is already in order. This requires 0 swaps. Welcome to the Bubble Sort Number Sorter. Enter values to add to list (Enter 0 to stop): 1 Enter values to add to list (Enter 0 to stop): 2 Enter values to add to list (Enter 0 to stop): 3 Enter values to add to list (Enter 0 to stop): 4 Enter values to add to list (Enter 0 to stop): 5 Enter values to add to list (Enter 0 to stop): 0 This sorting algorithm requried 0 swaps

In: Computer Science

Python #Exercise 1 #Assign the following first names to a variable name as a list: peter,paul,mary...

Python

#Exercise 1
#Assign the following first names to a variable name as a list: peter,paul,mary
#Assign the following last names to a variable name as a list: ng,lo,lau
#Display each first name in a separate line in turn so that your screen shows (ignore the #):
#peter
#paul
#mary
#Combine the elements in the list in turn so that you display the full names of each person in separate lines
#Output should look like the following (ignore the #):
#peter ng
#paul lo
#mary lau

#Exercise 2
#Assign the following grades to a variable name as a list: 80,90,100,70
#Use the sum() function to total up the values in the list and assign the sum to a variable
#Use the len() function to get the length of the list and assign the length to a variable
#Compute the average grade using the sum and length of the list and assign the average to a variable
#Convert the list length, list sum, and average to strings
#Display the results of your calculation in the following format using the + concatenator
#Your total score for [length of list] grades is [sum of list] resulting in an average of [average grade]!
#Ask the user for a grade using the prompt: New grade? (include a space after the ?)
#Convert the new grade into an integer
#Add the new grade to the end of the existing list using the append method
#Remove the second grade in the list using the pop method
##Use the sum() function to total up the values in the list and assign the sum to a variable
#Use the len() function to get the length of the list and assign the length to a variable
#Compute the average grade using the sum and length of the list and assign the average to a variable
#Display the results of your calculation in the following format using the + concatenator
#Your total score for [length of list] grades is [sum of list] resulting in an average of [average grade]!

#Exercise 3
#Ask the user for a student's name using the propmt: Student Name? (include a space after the ?)
#Assign the following grades to a variable name as a list: 80,90,70,85
#Assign the following requirement codes to a variable name as a list: HW,MT,IC,HW
#Ask the user for a new requirement code using the prompt: Requirement Code? (include a space after the ?)
#Ask the user for a new grade using the prompt: Grade? (include a space after the ?)
#Add the new requirement code to the requirement code list using the append method
#Convert the new grade to an integer
#Add the new grade to the end of the list of grades using the append method
#Display the following: Grades for: [student name -- input from user in first instruction of Exercise 3]
#Combine the information from both lists to display each pair of requirement code and grade in a separate line
#The output should have the following structure:
#[requirement code] [grade]
#For example, the first two lines should read (ignore the #)
#HW 80
#MT 90
#etc until the last items in the lists -- There should be 5 lines of code-grade pairings
#Get the sum of the grades list using the sum() function
#Get the length of the grades list using the len() function
#Compute the student's average grade using the sum and length
#Convert the average grade to a string
#Use the + concatenator to display the following statement (ignore the #):
#[student name]: your average grade is [average grade]!
#If student name is George Smith and average grade is 80, output should be:
#George Smith: your average grade is 80!

In: Computer Science

Using the implementation of the array based list given, write a CLIENT method (that is NOT...

Using the implementation of the array based list given, write a CLIENT method (that is NOT part of the class) called replace, that given a value and a position replaces the value of the element at that position. REMEMBER error checking

public static void replace( List aList, int newValue, int position)

public class ArraybasedList implements MyListInterface{
  private static final int DEFAULTSIZE = 25;
  
// Data members:
  private int currentSize;
  private int maxSize;
  private S[] elements;

  //default constructor has NO parameters
  public ArraybasedList(){
    this.currentSize =0;
    this.maxSize = DEFAULTSIZE;
    this.elements = (S[]) new Object[maxSize];
  }
  
  // non-default constructor
  public ArraybasedList(int maxElements) {
    if (maxElements <= 0)
      throw new ListException("The size of the list must be > zero.");
    
    this.currentSize =0;  // set the current size to zero
    this.maxSize = maxElements; // store the size in maxSize

// allocate storage for elements
    this.elements = (S[] ) new Object[this.maxSize];  

 }

  // begin implementing methods
  /**
*  This method returns true if the current
*  size of the list is zero.
*
*  
*
*/
  public boolean isEmpty() {
   return ( this.currentSize == 0); 
  }
  
  /**
*  This method returns true if the current
*  size of the list equals the maximum size 
*  of the list.
*
* 
*
*/
  public boolean isFull(){
    return ( this.currentSize == this.maxSize);
  }
  
  
/**
*  This method returns the maximum number
*  of elements the list can hold.
*
*  
*
*/   
  public int getMaxSize(){
    return this.maxSize;
  }

/**
*  This method returns the current number
*  of elements in the list.
*
*  
*
*/   
  public int size(){
    return this.currentSize;
  }
 
  /**
*  This method inserts the value at the given position.
*
*  
*  @param   position location where new value is to be inserted, 0<=position<=current size
*  @param   value new value to be added to the list
*
*/   
  public void add( int position, S value){
//� If the list is full EROR
//� if the position given is < 0 OR > current size, ERROR
//� If position given equals current size, add new element to the end
//� Otherwise, shift all elements whose position is equal to or greater than the given logical position, forward (up) on position in the list and add the new value
  if (this.isFull())
    throw new ListException("Invalid operation, can't add to a full list");
  
  if (position < 0 || position > this.currentSize)
    throw new ListException("Invalid operation, position must be between 0 and " + this.currentSize);
  
  if (position == this.currentSize)
    this.elements[currentSize] = value;
  else{
    for( int i= this.currentSize-1;  i >= position;  i--)
      this.elements[i+1] = this.elements[i];
    
    this.elements[position] = value;
  }
  this.currentSize++;
  }// end add at position
  
  /**
*  This method adds a new value to the end of a list.
*
* 
*  @param   value new value to be added to the list
*
*/   
   public void add( S value){
  this.add( this.currentSize, value);
}// add at end

   public S remove(int position) {
// Precondition:  The is list not empty.
// Precondition:  0<= position <= current size-1 of list
 S tempValue;
 
  if ( this.isEmpty() || position > currentSize-1 || position < 0 )
   throw new ListException("This delete can not be performed "
    + "an element at position " + position 
    + " does not exist " );


//1. Remove the desired value, and shift elements

// Store the value in the list to be deleted
// NOTE:  it must be cast to type S   
 tempValue = (S)this.elements[position];
 
// Shift existing elements down one position
// The logical position, is translated to the physical location of
// position -1
  for( int i = position;  i < this.currentSize-1;  i++)
    this.elements[i] = this.elements[i+1];
//2. Decrement the element count.
// Reinitialize the �old� end element to null, and decrement element count
  this.elements[currentSize-1] = null;
  currentSize--;
  return tempValue;
  } // end remove
/**
 * This method removes all occurrences of elements in the list argument from the list object
 * 
 * 
 * 
 * 
 * */
   public boolean removeAll(MyListInterface list){
   // iterate through the list parameter removing each occurrence of 
   // the values it contains
     boolean result=false;

   return result;
   }  
/**
*  This method returns the value at a specific
*  position in the list.  
*
* 
*  @param   position: location of element to return 0<=position

List interface:

public interface MyListInterface<S>{

/**
*  This method returns true if the current
*  size of the list is zero.
*
*  
*
*/
  public boolean isEmpty();
   
/**
*  This method returns true if the current
*  size of the list equals the maximum size 
*  of the list.
*
*  
*
*/
  public boolean isFull();

/**
*  This method returns the maximum number
*  of elements the list can hold.
*
* 
*
*/   
   public int getMaxSize();

/**
*  This method returns the current number
*  of elements in the list.
*
*  
*
*/   
   public int size();

/**
*  This method searches the list for the
*  specified value and returns the index
*  number of the first element containing
*  the value or -1 if the value is
*  not found.
*
*  
*  @param   value:  the search value
*  @return  index of element containing value or -1
*
*/   
  public int find( S value);

/**
*  This method returns the value at a specific
*  position in the list.  
*
*  
*  @param   position: location of element to return 0<=position<current size
*
*/   
   public S get( int position);

/**
*  This method inserts the value at the given position.
*
*  
*  @param   position location where new value is to be inserted, 0<=position<=current size
*  @param   value new value to be added to the list
*
*/   
   public void add( int position, S value);

/**
*  This method adds a new value to the end of a list.
*
*  
*  @param   value new value to be added to the list
*
*/   
   public void add( S value);
   
   
/**
 * This method removes all occurrences of elements in the list argument from the list
 * 
 * 
 * 
 * 
 * */
   public boolean removeAll(MyListInterface<? extends S> list);
 
   /**
 * This method removes and returns the value at position.  0<= position < currentSize
 * 
 * 
 * 
 * 
 * */
   public S remove(int position);
   
/**
*  This method deletes all of the list's contents.
*
*  
*
*/  
  public void clear();
 
/**
*  This method display the contents of the list
*
*  
*
*/
   public String toString();
}

In: Computer Science

Please only edit the list.cpp file only, implement the push_front method that will insert a new...

Please only edit the list.cpp file only, implement the push_front method that will insert a new element to the front of the list.

//list.h

// Doubly linked list
#ifndef Q2_H
#define Q2_H

template<typename T> class List;
template<typename T> class Iterator;

template <typename T>
class Node {
   public:
       Node(T element);
   private:
       T data;
       Node* previous;
       Node* next;
   friend class List<T>;
   friend class Iterator<T>;
};

template <typename T>
class List {
   public:
       List(); // Constructor
       ~List(); // Destructor
       void push_front(T element); // Inserts to front of list
       Iterator<T> begin(); // Point to beginning of list
       Iterator<T> end(); // Point to past end of list
   private:
       Node<T>* head;
       Node<T>* tail;
   friend class Iterator<T>;
};


template <typename T>
class Iterator {
   public:
       Iterator();
       T get() const; // Get value pointed to by iterator
       void next(); // Advance iterator forward
       void previous(); // Advance iterator backward
       bool equals(Iterator<T> other) const; // Compare values pointed to by two iterators
   private:
       Node<T>* position; // Node pointed to by iterator
       List<T>* container; // List the iterator is used to iterate
   friend class List<T>;
};

#endif

//list.cpp

// Implement the push_front method

#include <string>
#include "q2.h"

using namespace std;

// Node class implemenation

template <typename T>
Node<T>::Node(T element) { // Constructor
   data = element;
   previous = nullptr;
   next = nullptr;
}

// List implementation

template <typename T>
List<T>::List() {
   head = nullptr;
   tail = nullptr;
}


template <typename T>
List<T>::~List() { // Destructor
   for(Node<T>* n = head; n != nullptr; n = n->next) {
  
       delete n; //Deconstructor create an error evertime i ran it.
   }

}

template <typename T>
void List<T>::push_front(T element) {
   // Your code here
}


template <typename T>
Iterator<T> List<T>::begin() {
   Iterator<T> iter;
   iter.position = head;
   iter.container = this;
   return iter;
}

template <typename T>
Iterator<T> List<T>::end() {
   Iterator<T> iter;
   iter.position = nullptr;
   iter.container = this;
   return iter;
}

// Iterator implementation

template <typename T>
Iterator<T>::Iterator() {
   position = nullptr;
   container = nullptr;
}


template <typename T>
T Iterator<T>::get() const {
   return position->data;
}

template <typename T>
void Iterator<T>::next() {
   position = position->next;
}

template <typename T>
void Iterator<T>::previous() {
   if (position == nullptr) {
       position = container->tail;
   } else {
       position = position->previous;
   }
}

template <typename T>
bool Iterator<T>::equals(Iterator<T> other) const {
return position == other.position;
}

list_test.cpp

// Test for push_front method
#include <iostream>
#include "q2.h"
#include "q2.cpp"
using namespace std;

int main() {
   List<string> stack;
   stack.push_front("My");
   stack.push_front("name");
   stack.push_front("is");
   stack.push_front("Ozymandias");
   stack.push_front("king");
   stack.push_front("of");
   stack.push_front("kings");

   // Should print - kings of king Ozymandias is name My
   for (auto p = stack.begin(); !p.equals(stack.end()); p.next())
       cout << p.get() << " ";
   cout << endl;

}

In: Computer Science

python coding Suppose a list of positive numbers is given like the following list (remember this...

python coding

Suppose a list of positive numbers is given like the following list (remember this is only an example and the list could be any list of positive numbers) exampleList: 15 19 10 11 8 7 3 3 1 We would like to know the “prime visibility” of each index of the list. The “prime visibility” of a given index shows how many numbers in the list with indexes lower than the given index are prime. For instance, in the examplList, the “prime visibility” of the index 4 is 2 because there are 2 numbers (19 and 11) before index 4 that are prime. To solve this problem, design and implement a function called primeVisibility with two parameters: 1- The list of numbers 2- The index The function finds and returns the “prime visibility” of the given index.

In: Computer Science

Write an application that accepts up to 20 Strings, or fewer if the user enters the...

Write an application that accepts up to 20 Strings, or fewer if the user enters the terminating value ZZZ. Store each String in one of two lists—one list for short Strings that are 10 characters or fewer and another list for long Strings that are 11 characters or more. After data entry is complete, prompt the user to enter which type of String to display, and then output the correct list.

For this exercise, you can assume that if the user does not request the list of short strings, the user wants the list of long strings. If a requested list has no Strings, output The list is empty. Prompt the user continuously until a sentinel value, ZZZ, is entered.

import java.util.*;
public class CategorizeStrings
{
public static void main (String[] args)
{
// your code here
}

// display()
}

In: Computer Science

You must write each of the following scheme functions. You must use only basic scheme functions...

You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects.

Write a function named (list-replace ALIST SYM VAL) that accepts a list of elements and returns that list where all SYM's (a single symbol) have been replaced by the VAL (some scheme value). The replacement must occur even within nested lists. For example:

(list-replace '(a b c) 'a 3) ---> (3 b c)
(list-replace '(a (a b c) c) 'a 3) ---> (3 (3 b c) c)
(list-replace '() 'a 3) ---> ()
(list-replace '(a (a (a))) 'a '(3)) --> ((3) ((3) ((3))))

In: Computer Science