N JAVA
Objectives
Practice Link list, List node, compareTo, user defined data type, interfaces
Movie List
Create a link list of the movies along with the rating, number of the people who watched the movie and the genre of the movie.
Required classes
Movie class implements Comparable
Attributes: movie’s name, genre, rating, number of people watched
Methods: constructor, getter, setter, equals, compreTo, toString
ListNode class
Attributes: each node has two attributes
Methods:
Constructors
public ListNode(Movie m): initializes the instance variable
m
public ListNode() : empty body
public ListNode(Movie m, ListNode next): initializes the instance variables m and next
getter methods
public Movie getMovie()
public ListNode getNext()
setter methods
public void setNext(ListNode next)
List interface
public void add(String name, String ganra, int star, int
people);
public void add(int index, String name, String genre, int star, int
people); public int indexOf(String movieName);
public void remove(String movieName);
public int size();
public String toString();
public Movie get(int position);
MovieList implements List :
all the methods in this class must use link list concept
public class MovieList implements List
{
private ListNode front;
public static int size = 0;
//constructor
public MovieList(){}
//add the movie to the end of the list
public void add(String name, String ganra, int star, int people){}
//adds the movie at the given index
public void add(int index, String name, String ganra, int star, int people){}
//returns the movie at the given index
public int indexOf(String movieName){}
//removes the movie from the list
public void remove(String movieName){}
//returns the size of the list
public int size(){}
//create a string from all the movies in the list
public String toString(){}
//returns the movie at the given index
public Movie get (int pos){} //returns the list of the movie with the give star
public String getMovie(int star){}
//return the movie with the max number of peopel watched.
public Movie mostWatched(){}
Driver class
Make sure that your code works with the following driver. Copy and paste this class to your file.
class Driver
{
public static void main (String [] args)
{
MovieList list = new MovieList();
list.add("Reservoir Dogs", "drama",5, 20000);
list.add("Airplane", "Funny", 3, 1200);
list.add("Doctor Zhivago","comedy", 4,23000);
list.add("The Deer Hunter", "Family", 3, 2345);
System.out.println("Here is the list of the movies\n");
System.out.println(list);
System.out.println("\nhere is the the movie that was most
watched");
System.out.println(list.mostWatched());
System.out.println("Here is the list of 5 stars ratings");
System.out.println(list.getMovie(5));
System.out.println("removing Reservoir movie");
list.remove("Reservior Dogs");
System.out.println(list);
System.out.println("Displaying the second movie in the
list");
System.out.println(list.get(1));
System.out.println("adding a movie at position 2");
list.add(2, "Up", "Carton",3,4500);
System.out.println(list);
int i = list.indexOf("Up");
System.out.println("The movie up is in the position " + i);
}
}
Sample output
Here is the list of the movies
Reservoir Dogs, drama, *****, 20000
Airplane, Funny, ***, 1200
Doctor Zhivago, comedy, ****, 23000
The Deer Hunter, Family, ***, 2345
here is the the movie that was most watched
Doctor Zhivago, comedy, ****, 23000
Here is the list of 5 stars ratings
Reservior Dogs, drama, *****, 20000
removing Reservoir movie
Airplane, Funny, ***, 1200
Doctor Zhivago, comedy, ****, 23000
The Deer Hunter, Family, ***, 2345
Displaying the second movie in the list
Doctor Zhivago, comedy, ****, 23000
adding a movie at position 2
Airplane, Funny, ***, 1200
Doctor Zhivago, comedy, ****, 23000
Up, Carton, ***, 4500
The Deer Hunter, Family, ***, 2345
The movie up is in the position 2
In: Computer Science
in python please
Q1) Create a Singly link list and write Python Programs for the following tasks: a. Delete the first node/item from the beginning of the link list b. Insert a node/item at the end of the link list c. Delete a node/item from a specific position in the link list
Q2) Create a Singly link list and write a Python Program for the following tasks: a. Search a specific item in the linked list and return true if the item is found and display the node position otherwise return false. b. Reverse the link list.
In: Computer Science
Java Data Structure Doubly Linked List
/*
* Complete the swap(int index) method
* No other methods/variables should be added/modified
*/
public class A3DoubleLL<E> {
/*
* Grading:
* Swapped nodes without modifying values - 2pt
* Works for all special cases - 1pt
*/
public void swap(int index) {
//swap the nodes at index and
index+1
//change the next/prev connections,
do not modify the values
//do not use
delete/remove/insert/add to help with this process
//make sure to account for all
special cases
}
private Node start, end;
private int count;
public A3DoubleLL() {
start = end = null;
count = 0;
}
public String printList() {
String output = "";
Node current = start;
while(current != null) {
output +=
current.value + ",";
current =
current.next;
}
return output;
}
public String printListRev() {
String output = "";
Node current = end;
while(current != null) {
output +=
current.value + ",";
current =
current.prev;
}
return output;
}
public void add(E val) {
Node newItem = new Node(val);
if(start == null) {
start =
newItem;
end =
start;
count = 1;
} else {
end.next =
newItem;
newItem.prev =
end;
end =
newItem;
count++;
}
}
public void insert(E val, int index) {
if(index < 0) {//fix invalid
index
index = 0;
}
if(index >= count) {//goes in
last position
this.add(val);
} else {
Node newItem =
new Node(val);
if(index == 0)
{//goes in first position
newItem.next = start;
start.prev = newItem;
start = newItem;
} else {//goes
in middle
Node current = start;
for(int i = 1; i < index; i++) {
current = current.next;
}
newItem.next = current.next;
newItem.prev = current;
current.next.prev = newItem;
current.next = newItem;
}
count++;
}
}
public void delete(int index) {
if(index >= 0 && index
< count) {//valid index
if(index == 0)
{//remove first
start = start.next;
if(start != null) {//as long as there was an
item next in list
start.prev = null;
} else {//if only item was removed
end = null;
}
} else if(index
== count-1) {//remove last item
end = end.prev;
end.next = null;
} else {//remove
middle item
Node current = start;
for(int i = 1; i < index; i++) {
current = current.next;
}
current.next = current.next.next;
current.next.prev = current;
}
count--;
}
}
public E get(int index) {
if(index >= 0 && index
< count) {//valid index
Node current =
start;
for(int i = 0; i
< index; i++) {
current = current.next;
}
return
current.value;
}
return null;
}
public String toString() {
return this.printList();
}
private class Node {
E value;
Node next, prev;
public Node(E v) {
value = v;
next = prev =
null;
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class A3Driver {
public static void main(String[] args) {
A3DoubleLL<Integer> list =
new A3DoubleLL<>();
for(int i = 1; i < 10; i++)
{
list.add(i);
}
System.out.println("Before
Swap");
System.out.println(list.printList());
System.out.println(list.printListRev());
list.swap(4);
System.out.println("After
Swap");
System.out.println(list.printList()
+ ":1,2,3,4,6,5,7,8,9,");
System.out.println(list.printListRev() +
":9,8,7,6,5,4,3,2,1,");
System.out.println();
System.out.println("Hot
Potatoe");
A3CircleLL hotPotato = new
A3CircleLL();
hotPotato.playGame(5, 3);
System.out.println("Correct:");
System.out.println("Removed Player
4\nRemoved Player 3\nRemoved Player 5\nRemoved Player 2\nWinning
player is 1");
System.out.println();
A3Queue<Integer> queue = new
A3Queue<>();
queue.enqueue(5);
queue.enqueue(20);
queue.enqueue(15);
System.out.println(queue.peek()+":5");
System.out.println(queue.dequeue()+":5");
queue.enqueue(25);
System.out.println(queue.dequeue()+":20");
System.out.println(queue.dequeue()+":15");
}
}
In: Computer Science
(C++ with main to test)
2.2
Task 1
You are going to implement a variant of the standard linked list,
the circular list. The
circular linked list is a variant of the standard linked list that
wraps around so that
traversals through the list will wrap around to the beginning
instead of simply reaching
the end. This will consist of implementing two classes: cLL and
item.
2.2.1
cLL
The class is described according to the simple UML diagram
below:
2cLL<T>
-head:item<T> *
-size:int
------------------------
+cLL()
+~cLL()
+isEmpty():bool
+getSize():int
+push(newItem: item<T>*):void
+pop():item<T>*
+getMaxItem():T
+getMinItem():T
+peek(): item<T> *
+printList():void
The class variables are as follows:
• head: The head pointer for the linked list.
• size: The current size of the circular linked list. It starts at
0 and grows as the list
does.
The class methods are as follows:
• cLL: The constructor. It will set the size to 0 and initialise
head as null.
• ∼cLL: The class destructor. It will iterate through the circular
linked list and
deallocate all of the memory assigned for the items.
• isEmpty: This function returns a bool. If the circular linked
list is empty, then it
will return true. Otherwise, if it has items then it will return
false.
• getSize: This returns the current size of the circular linked
list. If the list is empty
the size should be 0.
• push: This receives a new item and adds it to the circular linked
list. It is added to
the front of the list. The front being the head of the list.
• pop: This receives, and returns, the first element in the list.
The first element is
removed from the list in the process. If the list is empty, return
null. The first
element referring to the head pointer in this case.
• peek: This function returns the first element in the list but
does not remove it, first
being the head item.
• getMaxItem: This will return the value of the item in the
circular linked list which
is the maximum for the list.
• getMinItem: This will return the value of the item in the
circular linked list which
is the minimum for the list.
3• printList: This will print out the entire list from head
onwards. Importantly, each
item is listed on one line with commas delimiting each item. For
example,
1.2,1.3,1,4,5,6
Remember to add a newline at the end.
2.2.2
item
The class is described according to the simple UML diagram
below:
item <T>
-data:T
-------------------
+item(t:T)
+~item()
+next: item*
+getData():T
The class has the following variables:
• data: A template variable that stores some piece of
information.
• next: A pointer of item type to the next item in the linked
list.
The class has the following methods:
• item: This constructor receives an argument and instantiates the
data variable with
it.
• ∼item: This is the destructor for the item class. It prints out
”Item Deleted” with
no quotation marks and a new line at the end.
• getData: This returns the data element stored in the item.
You will be allowed to use the following libraries:
cstdlib,string,iostream.
In: Computer Science
Can you solve it for me plz?
‘Lakeside Manufacturing’ is a boating company that specializes in sailboats for sailing schools and Jules Paulson is the owner of the company. His lead foreman and second in command is Kevin Hill. There are a small core group of 15 employees who are fulltime and experienced in their trade and sailing. Unfortunately, over the summertime, the permanent employees like to take their vacation so they can go sailing. ‘Lakeside Manufacturing’ makes sure that at any given time over the summertime period, only 25% of the permanent staff are away at any given time so that 75% are still doing their usual jobs. This has worked to some extent; however, there are times the company feels short staffed.
Last year, Kevin had an idea that over the summer, they could hire some seasonal workers to do the work of those who are away. Kevin spoke to Jules and said that maybe they could hire students from the local university during the summer to do some of the tasks. Part of the requirement was that they either should have some boating experience or be able to know some of the woodworking or electrical work. Summer last year, it did not work so well because the students started and were randomly placed to fill gaps among the teams where the full-time employees were away on vacation. There were some challenges and tensions that would arise because the students were not as skilled at the work that the experienced employees were. Added to that, the students would have headphones on while working, taking texting moments or take breaks when they felt like and had a different perspective and attitude about the work. This annoyed some of the older experienced workers.
This year, Kevin thought that he would hire 10 students over the summer but instead of having them integrate into the work that was being done by the older more senior workers, he thought that it might be better to have all the 10 students in one team and separate from the experienced workers who were there and somewhat annoyed by the behaviour of the students. Kevin trained the students and was their liaison so that any questions or problems would be answered by him. A number of the students came back from last year so that the training was not too difficult. He also outlined what they needed to do and was less rigid on breaks and how the work was done, except that things had to be completed with care, quality and on time.
As the summer went on, the students got very good at their tasks because they were good with technology and also knew that if they would finish early, they could have free time. A healthy rivalry and competition started to emerge between the experienced workers and the students. It was productive and things were working out…for a while. Eventually, the student employees would say how fast they could work, and the older employees were slower. It was also not uncommon for the students to head over to where the older employees were working and make comments, which started to make the more experienced employees annoyed. The organization started to see two camps of employees instead of everyone working together.
Now, instead of everyone working together and feeling like they were part of ‘Lakeside Manufacturing’, both sides were either making fun of the other side or hiding tools and supplies from the other side so it would slow the other side down. It was starting to get out of hand and the owner, Jules Paulson, called Kevin Hill in to his office and said that he thinks that it might be better to not have the two sides and it might be better to just break both sides up and reassign the teams so they were all working together. Kevin thought that this might not be a good idea because he was pretty sure most, if not all, of the students would quit. Kevin has called you for your advice and thoughts on how to resolve this situation.
a) Apply some concepts from the course to explain what is going on at ‘Lakeside Manufacturing
b) Take a position on if the teams should be broken up or not and explain why
c) Based on your answer in (b) what do you recommend helping improve the situation
In: Operations Management
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list functionality. The functions header file is also given. Complete the functions of the header file linked_list.h below.
=========================================================
// listmain.cpp
#include "Linked_List.h"
int main(int argc, char **argv)
{
float
f;
Linked_List *theList;
cout << "Simple List
Demonstration\n";
cout << "(List implemented as an
Array - Do not try this at home)\n\n";
cout << "Create a list and add a few
tasks to the list";
theList = new Linked_List(); // Instantiate a list object
theList->Insert(5, 3.1f); // Note:
The argument to the funtion should be a float
theList->Insert(1, 5.6f); // A constant
real number like 3.1 is interpreted as
theList->Insert(3, 8.3f); // a double
unless it is explicitly defined as a float
theList->Insert(2, 7.4f); // by adding
an 'f' to the end of the number.
theList->Insert(4, 2.5f);
// Show what is in the list
theList->PrintList();
// Test the list length function
cout << "\nList now contains "
<< theList->ListLength() << "items.\n\n";
// Test delete function
cout << "Testing delete of last item
in list.\n";
theList->Delete(4);
theList->PrintList();
// Test delete function
cout << "Testing delete of first
item in list.\n";
theList->Delete(5);
theList->PrintList();
// Test delete function
cout << "Testing delete of a middle
item in list.\n";
theList->Delete(3);
theList->PrintList();
// Test delete function with a known
failure argument
cout << "Testing failure in delete
function.\n";
if(theList->Delete(4))
cout
<< "Oops! Should not have been able to delete.\n";
else
cout
<< "Unable to locate item to delete.\n";
// Test search (known failure)
cout << "Testing Search function.
Search for key 3\n";
if(theList->Search(3, &f))
cout
<< "Search result: theData = %f\n", f;
else
cout
<< "Search result: Unable to locate item in list\n";
// Test search (known success)
cout << "Testing Search function.
Search for key 2\n";
if(theList->Search(2, &f))
cout
<< "Search result: theData = " << f <<
"\n";
else
cout
<< "Search result: Unable to locate item in list\n";
cout << "\n\nEnd list demonstration...";
return 0;
}
========================================================================================
// linked_list.h functions
#include
using namespace std;
// Define a structure to use as the list item
struct ListItem
{
int
key;
float theData;
ListItem *next;
};
class Linked_List
{
private:
ListItem
*head;
// Pointer to head of the list
public:
Linked_List();
// Class constructor
~Linked_List();
// Class destuctor
void
ClearList();
// Remove all items from the list
bool
Insert(int key, float f);// Add an item to the list
bool
Delete(int key); //
Delete an item from the list
bool
Search(int key, float *retVal); // Search for an item in the
list
int
ListLength();
// Return number of items in list
bool
isEmpty();
// Return true if list is empty
bool
isFull();
// Return true if list is full
void
PrintList();
// Print all items in the list
};
#endif // End of list header
In: Computer Science
Write a python programA3) Lambda Expressions. Use lambda expression to sort the list ["democratic", "republican", "equal", "python", "break", "two", "ruby"] by: a) the last 2 characters of each list item in reverse order b) create new list from list above where each item has only 3 characters and first one is capitalized. For example, the list item = "democratic" will transform into "Dem". Apply alphabetically sorting to the new list.
In: Computer Science
C++: Write a reverse function that receives a reference to a integer linked list and reverses the order of all the elements in it. For example, if the input linked list is 1 -> 4-> 2-> 3-> 6-> 5}, after processing by this function, the linked list should become 5-> 6-> 3-> 2-> 4-> 1. You need to write a main file to insert elements into the linked list and call the reverseLinkedList() function which takes the reference of first node of linked list and returns the reference of first node, after reversing the linked list. [User Input is not necessary]. Note: Do not use built in library function for linked list. You need to define your own linked list.
In: Computer Science
write code to manage a linked list using recursive approach. (Using this code) C++ IN Unix.
// app.cpp
#include <iostream>
#include "linkedlist.h"
using namespace std;
void find(LinkedList& list, char ch)
{
if (list.find(ch))
cout << "found ";
else
cout << "did not find
";
cout << ch << endl;
}
int main()
{
LinkedList list;
list.add('x');
list.add('y');
list.add('z');
cout << list;
find(list, 'y');
list.del('y');
cout << list;
find(list, 'y');
list.del('x');
cout << list;
find(list, 'y');
list.del('z');
cout << list;
find(list, 'y');
return 0;
}
//-------------------
//linkedlist.h
#ifndef _LINKED_LIST_
#define _LINKED_LIST_
#include <ostream>
class LinkedList
{
public:
LinkedList();
~LinkedList();
void add(char ch);
bool find(char ch);
bool del(char ch);
friend std::ostream&
operator<<(std::ostream& out, LinkedList&
list);
};
#endif // _LINKED_LIST_
//-------------------------
//makefile
CC = g++
CPPFLAGS = -Wall -g -std=c++11
app: app.o linkedlist.o
app.o: linkedlist.h
linkedlist.o: linkedlist.h
.PHONY: clean
clean: # clean
the directory
$(info --
cleaning the directory --)
rm -f *.o
rm -f app
//-----------------------
In: Computer Science
Case Study: A Tale of Two Classes
Ebony Ellis has two communication classes back-to-back in the same room, but they couldn’t be more different. The first, a class on interpersonal communication, is taught by Steve Gardner, an older professor who has taught at the university for 20 years. The first day of class he verbally explained the rules for class conduct, which were also distributed in a printed handout—cell phones off, no texting, and, unless a student needs to use one for taking notes, laptops closed. Class starts on time and ends on time, and students should try not to leave early. Ebony’s second class, an organizational communication course taught by Marissa Morgan, a younger professor in her 40s, has different rules. There aren’t any. This professor doesn’t care if the students use their laptops during class. Texting and talking are unrestrained. Professor Morgan announced on the first day that all students are responsible for their own learning in the class, and she trusts them to know how they learn best. When students walk in late or leave early, she always says hello or goodbye to them. Ebony likes her interpersonal communication class a lot. Professor Gardner’s manner has succeeded in getting the class of 75 students to engage with him and listen to one another. Personal disclosures by students and the professor alike are frequent, and there is often much humor and laughter. Even though it is a large class, most people know each other’s names, as does Professor Gardner. Many of the students do things with each other outside of class. In his course, students write a reflection paper every other week, and they have a midterm and final exams.
The atmosphere in the organizational communication class is strikingly different to Ebony. It is spontaneous and uncontrolled. Sometimes professor Morgan lectures, but most of the time she just comes to class and invites students to discuss whatever they want to talk about. Students do not know each other’s names and seldom connect with each other outside of class. Professor Morgan also assigns papers, but they are short, personal observation papers that aren’t given grades but are marked as turned in or not. Students’ final grades for the class are dependent on a presentation each student must give on an interpersonal communication topic of his or her choice. Ebony thinks the two differing styles of the professors would make a great topic for her organizational communication class presentation. To get more information, she interviews both instructors to learn why their classroom management styles are so different. Professor Gardner describes his teaching philosophy this way: “I want students to think that this class is unique and the subject is important and has value. I know all students by name, and I allow them to call me by my first name or my title. I really want them to be on board with the direction the train is going from the start. I try to build a community by getting the students to listen to one another. The fun and spirit of the class comes from the camaraderie they establish. In order to listen to one another, however, they have to be fully present. To be fully present, they have to be paying full attention. Texting and open laptops suggest to me that the students are disassociated and disconnected from the group. The attention is on self, rather than the community.” Professor Morgan says her goal is to be sure to cover the required course content and still enjoy the teaching experience. “I give the students just enough freedom in class that they will either sink or swim. This freedom allows me to present my ideas, and then they are free to discuss them as they wish. I think today’s students are so multifaceted that they can find their own way to learn, even if it involves texting or using their laptops during class. Many times a student will bring up something valuable that he or she has found while surfing the Internet during class that really adds to our discussions. As I see it, my role as a professor is to present the material to be learned, while the students are responsible for how much of it they can absorb.” Ebony also interviewed two students, like herself, who are enrolled in both classes. Ian said he is very pleased with Professor Gardner’s class because he knows what is expected of him and what the norms for class behavior are, noting “He’s the only prof at the U who knows my name.” Professor Gardner’s grading structure is similar to that of most other classes Ian has had, and he likes that there are several graded assignments that allow him to know how he is doing through the course of the semester. As for Professor Morgan’s class, he thinks it is “OK” but finds it distracting when people are texting in class. Ian is also stressed about his grade being dependent on one big assignment. Professor Gardner’s class is also BreeAnn’s favorite. She says that Professor Morgan’s class feels “a little wild,” the discussions are not controlled by the professor so the class does not stay on topic, and you learn very little. While Professor Morgan writes thoughtful comments on each of their papers, it is unclear how the papers are related to her lectures and more importantly the student’s final grade. BreeAnn finds the final presentation assignment to be an interesting challenge but irrelevant to the class and her major. “They are both good,” Ian says, “just very, very different.”
Questions
In establishing a constructive climate for his or her class, what kind of structure has each professor put in place?
How would you describe the group norms for each class?
What actions has each professor taken to establish cohesiveness in his or her class?
What standards of excellence has each professor established for his or her course?
Which class atmosphere would you do best in? Why?
In: Psychology