If I have a class named classroom, a classroom class consists of five methods:
1. void add(T newStudent) //add a student
2. void set(int pos, T student) //changes the student stored at position pos to be the student parameter
3. T get(int pos)//returns the student at position pos.
4. int size() //num of student in a classroom
5. String toString()
-------------------------------------------------------------------------------------------------------------------------------
In another class recursionWS
static <T> boolean studentInList (classroom<T> list1, classroom<T> list2){
//this method returns true if students in list1 appears in the same order in list2.
//if in list1 I have {a,r,g} and list2 I have {s,f,a,r,d,r,v,g}
//a,r,g in list1 appeared in the same order in list2 (r after a and g after r). this should return true.
//else return false;
}
How do I write this without using any type of loops and just use recursion?
boolean studentList(classromm<T> list1, classroom<T> list2){
List<T> tmp = new ArrayList<T>();
if(list1.size() > list2.size()){
tmp = list1;
list1 = list2;
list2 = tmp
}
if(list1 == null){
return true;
}
for(int k=0;k<list2.size();k++){
if(list1.get(0) == list2.get(k)){
return studentList(list1.get(1) , list2.get(k+1));
}
}
return false;
}
If I have a class named classroom, a classroom class consists of five methods: 1. void...
Add the following method to xxxxxp3: // deletes x from sorted list k if exist, k = 0, 1, 2 private void delete(x, k) // returns position of x in sorted list k if exist otherwise, -1. k = 0, 1, 2 private int search(x, k) import java.util.Scanner; class xxxxxp3{ private node[] head = new node[3]; private class node{ int num; node link; node(int x){ num=x; link = null; } } public void prtlst(int k){ System.out.printf("\nContents of List-%d:",k); for(node cur...
Hi, I hope I can get some help with the following exercise in C++( CPP): 1.Write an additional method called push_back(int) that will add an integer to the end of the list. You can modify the provided code. 2.Modify the Node class and LinkedList class so that you can access your parent node (double linked-list). /* definition of the list node class */ class Node { friend class LinkedList; private: int value; Node *pNext; public: /* Constructors with No Arguments...
Please write in Java Recall that the ADT list class methods are; void List() bool isEmpty() int size() void add(int item, int pos)//inserts item at specified position (first postion is 1) void remove(int index)//removes item from specified position void removeAll() int indexOf(int item)//returns the index of item int itemAt(int index)//returns the item in position specified by index Implementation of LIST ADT operations and details are hidden. Only the methods listed above are...
Currently working on a Java Assignment. I have written most codes for swap, reverse and insert. Just need a. itemCount receives a value and returns a count of the number of times this item is found in the list. c. sublist receives two indexes and returns an ArrayList of node values from the first index to the second index, provided the indexes are valid. d. select receives a variable number of indexes, and returns an ArrayList of node values corresponding...
I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student { private String firstName; private String lastName; private String id; private boolean tuitionPaid; public Student(String firstName, String lastName, String id, boolean tuitionPaid) { this.firstName=firstName; this.lastName=lastName; this.id=id; this.tuitionPaid=tuitionPaid; } ...
C++ comment code Comment the following code #include <iostream> using namespace std; class Node { public: Node(int val); int value; Node* next; }; Node::Node(int val){ value = val; } class List { public: List(); // Uncomment the line below once you're ready List(List &other); void push_front(int value); bool pop_front(int &value); void push_back(int value); bool pop_back(int &value); int at(int index); void insert_at(int index, int value); void remove_at(int index); int size(); private: // other members you may have used Node* head; Node*...
Code must only be written in IntegerLinkedList.java. 9 Methods need to be implemented so that all the tests in the tester file passes. IntegerLinkedList.java implements IntegerNode.java Your task is to implement the interface described in the file IntegerList.java using a doubly linked list in the file IntegerLinkedList.java. Your implementation must be a doubly-linked list that maintains both a head and a tail reference. You've also been provided with a node class (IntegerNode.java) that includes a prev and next references. //IntegerList.java...
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Write a recursive method in java that accepts a integer as its argument and returns true if it is palindrome, false otherwise. public class Recursion { public static void main(String[] args) { Recursion r = new Recursion(); System.out.println(“Is 12321 a palindrome? “+ra.isPalindrome(12321)); //true } public Boolean isPalindrome(int num){ return false;...
Requirements: Finish all the functions which have been declared inside the hpp file. Details: string toString(void) const Return a visible list using '->' to show the linked relation which is a string like: 1->2->3->4->5->NULL void insert(int position, const int& data) Add an element at the given position: example0: 1->3->4->5->NULL instert(1, 2); 1->2->3->4->5->NULL example1: NULL insert(0, 1) 1->NULL void list::erase(int position) Erase the element at the given position 1->2->3->4->5->NULL erase(0) 2->3->4->5->NULL //main.cpp #include <iostream> #include <string> #include "SimpleList.hpp" using std::cin; using...