In: Computer Science
In java,
Finding the maximum value in a BST (Binary Search Tree). Students need to write the code.
In: Computer Science
Use the Universal Access utility to explore the different assistive technologies available within Fedora 20. Note the ones that you find useful.
In: Computer Science
Jojo is given N integers, A 1, A 2, ..., A N by his teacher. His teacher also give him an integer K and 2 M integers, L 1, L 2, ..., L M and R 1, R 2, ..., R M. For each i from 1 to M , his teacher asked him to calculate the sum of multiple of K index numbers from index L i to R i . For example if L i = 3 and R i = 10 and K = 3, then he has to calculate the value of ( A 3 + A 6 + A9). Help him by making the program to calculate it quickly!
Format Input:
The first line consist of three integers, N , M, and K. The second line consist of N integers, A 1, A 2, ..., A N . The next M lines consist of two integers, L i and R i.
Format Output:
Output M lines, the answer for L i and R i , where i is an integer from 1 to M.
Constraints
• 1 ≤ N, M ≤ 105
• 1 ≤ A i ≤ 102 • 1 ≤ K ≤ 10
• 1 ≤ L i ≤ R i ≤ N
Sample Input 1 (standard input):
5 3 2
100 3 1 87 6
1 1
1 5
3 4
Sample Output 1 (standard output):
0
90
87
Note: Use C language, don’t use function./recursive/void.
The input is N,M,K not only N &M.
In: Computer Science
I have added the MyList.java all the way on the bottom.
Thats all the detail I have for this and what kind of more detail information you need.
Plz Write the program in Java. And Plz post the running program with main and test.Thanks.
Implementing Lists:
Start by carefully reading Listing 24.5: MyLinkedList.java (on page 938 of the 11th Edition of the text). Note that the listing is incomplete. Your assignment is to implement a revised MyLinkedList class after you have included all the code needed to fill in and complete all the methods that were omitted. Next, write a (main) driver program that initializes a linked list with 10 names (your choice), and then completely tests every one of its methods of ensure that the class meets all its requirements.
Listing 24.5
MyLinkedList.java
1 public class MyLinkedList implements MyList {
2 private Node head, tail;
3 private int size = 0; // Number of elements in the list
4
5 /** Create an empty list */
6 public MyLinkedList() {
7 }
8
9 /** Create a list from an array of objects */
10 public MyLinkedList(E[] objects) {
11 for (int i = 0; i < objects.length; i++)
12 add(objects[i]);
13 }
14
15 /** Return the head element in the list */
16 public E getFirst() {
17 if (size == 0) {
18 return null;
19 }
20 else {
21 return head.element;
22 }
23 }
24
25 /** Return the last element in the list */
26 public E getLast() {
27 if (size == 0) {
28 return null;
29 }
30 else {
31 return tail.element;
32 }
33 }
34
35 /** Add an element to the beginning of the list */
36 public void addFirst(E e) {
37 // Implemented in Section 24.4.3.1, so omitted here
38 }
39
40 /** Add an element to the end of the list */
41 public void addLast(E e) {
42 // Implemented in Section 24.4.3.2, so omitted here
43 }
44
45 @Override /** Add a new element at the specified index
46 * in this list. The index of the head element is 0 */
47 public void add(int index, E e) {
48 // Implemented in Section 24.4.3.3, so omitted here
49 }
50
51 /** Remove the head node and
52 * return the object that is contained in the removed node.
*/
53 public E removeFirst() {
54 // Implemented in Section 24.4.3.4, so omitted here
55 }
56
57 /** Remove the last node and
58 * return the object that is contained in the removed node.
*/
59 public E removeLast() {
60 // Implemented in Section 24.4.3.5, so omitted here
61 }
62
63 @Override /** Remove the element at the specified position in
this
64 * list. Return the element that was removed from the list.
*/
65 public E remove(int index) {
66 // Implemented earlier in Section 24.4.3.6, so omitted
67 }
68
69 @Override /** Override toString() to return elements in the list
*/
70 public String toString() {
71 StringBuilder result = new StringBuilder("[");
72
73 Node current = head;
74 for (int i = 0; i < size; i++) {
75 result.append(current.element);
76 current = current.next;
77 if (current != null) {
78 result.append(", "); // Separate two elements with a comma
79 }
80 else {
81 result.append("]"); // Insert the closing ] in the string
82 }
83 }
84
85 return result.toString();
86 }
87
88 @Override /** Clear the list */
89 public void clear() {
90 size = 0;
91 head = tail = null;
92 }
93
94 @Override /** Return true if this list contains the element e
*/
95 public boolean contains(Object e) {
96 // Left as an exercise
97 return true;
98 }
99
100 @Override /** Return the element at the specified index
*/
101 public E get(int index) {
102 // Left as an exercise
103 return null;
104 }
105
106 @Override /** Return the index of the head matching element
in
107 * this list. Return −1 if no match. */
108 public int indexOf(Object e) {
109 // Left as an exercise
110 return 0;
111 }
112
113 @Override /** Return the index of the last matching element
in
114 * this list. Return −1 if no match. */
115 public int lastIndexOf(E e) {
116 // Left as an exercise
117 return 0;
118 }
119
120 @Override /** Replace the element at the specified
position
121 * in this list with the specified element. */
122 public E set(int index, E e) {
123 // Left as an exercise
124 return null;
125 }
126
127 @Override /** Override iterator() defined in Iterable */
128 public java.util.Iterator iterator() {
129 return new LinkedListIterator();
130 }
131
132 private class LinkedListIterator
133 implements java.util.Iterator {
134 private Node current = head; // Current index
135
136 @Override
137 public boolean hasNext() {
138 return (current != null);
139 }
140
141 @Override
142 public E next() {
143 E e = current.element;
144 current = current.next;
145 return e;
146 }
147
148 @Override
149 public void remove() {
150 // Left as an exercise
151 }
152 }
153
154 private static class Node {
155 E element;
156 Node next;
157
158 public Node(E element) {
159 this.element = element;
160 }
161 }
162 }
MyList.java public interface MyList extends java.lang.Iterable { //Add a new element at the end of this list public void add(E e); //Add a new element at the specified index in this list public void add(int index, E e); //Clear the list public void clear(); //Return true if this list contains the element public boolean contains(E e); //Return the element from this list at the specified index public E get(int index); //Return the index of the first matching element in this list. //Return -1 if no match. public int indexOf(E e); /** Return true if this list contains no elements */ public boolean isEmpty(); /** Return the index of the last matching element in this list * Return -1 if no match. */ public int lastIndexOf(E e); /** Remove the first occurrence of the element o from this list. * Shift any subsequent elements to the left. * Return true if the element is removed. */ public boolean remove(E e); /** Remove the element at the specified position in this list * Shift any subsequent elements to the left. * Return the element that was removed from the list. */ public E remove(int index); /** Replace the element at the specified position in this list * with the specified element and returns the new set. * */ public Object set(int index, E e); /** Return the number of elements in this list */ public int size(); }
In: Computer Science
I keep getting the error below in zbooks. How can I fix this. Thank You JAVA
zyLabsUnitTest.java:14: error: cannot find symbol s = MidtermProblems.difference(75, 75);
^ symbol: method difference(int,int) location: class MidtermProblems 1 error
import java.lang.Math;
public class MidtermProblems {
public static String difference(int a, int b) {
int diff = Math.abs(a - b);
String ans = "";
if (diff == 0) {
ans = "EQUAL";
} else if (diff > 10) {
ans = "Big Difference " + diff;
} else if (diff <= 10) {
ans = "Small Difference " + diff;
}
return ans;
}
}
In: Computer Science
I have a C problem. I need to read the data of a txt file to array by struct, then use these data to sum or sort.
The txt file and the struct like
aa.txt
1 2
3 4
*****************************
struct aaa{
int num1,num2;
}bbb[2];
num1 for 1,3, num2 for 2 4
I made a void readfile () function for read data. How can I pass the numbers to another function ( void sum () and void sort() ) for sum and sort
I finished the void readfile(), but I have no idea how to pass the value to another function.
I tries to use the pointer of struct, can you give me a general idea?
Because I must move data to an array, is my array of struct wrong? I mean if I need to use malloc
Thanks
In: Computer Science
Using the software Emulator EMU8086, write an assembly program that uses a loop to print "HELLO WORLD" 3 times and "LIFE" 2 times.
Example:
HELLO WORLD
HELLO WORLD
HELLO WORLD
LIFE
LIFE
In: Computer Science
Write a complete C++ program to implements a Min-heap.
Each node will contain a single integer data element. Initialize the Min-heap to contain 5 nodes, with the values 8, 12, 24, 32, 42.
The program should allow for the insertion and deletion of nodes while maintaining a Min-Heap.
The program should allow the user to output data in Preorder, Inorder and Postorder.
The program should loop with menu items for each of the above objectives and the choice to quit
Here's the code:
**EDIT: Need help in outputting data into Preorder, Inorder and Postorder, plus ensuring the nodes are implemented correctly (I think I overlooked this part). **
#include studio.h
#include isotream
int array[100]; // variable for array to store up to 100
elements
int n;
using namespace std;
void display();
void delete_elem(int num);
void heapify(int index,int n){
if(index >= n)return;
int left = 2*index;
int right = 2*index + 1;
int mx_ind = index;
if(left < n and array[left] > array[mx_ind]){
mx_ind = left;
}
if(right < n and array[right] > array[mx_ind]){
mx_ind = right;
}
if(mx_ind != index){
swap(array[mx_ind],array[index]);
heapify(mx_ind,n);
}
}
int insert(int num, int location)
{
int parentnode;
while (location > 0)
{
parentnode =(location - 1)/2;
if (num <= array[parentnode])
{
array[location] = num;
return location;
}
array[location] = array[parentnode];
location = parentnode;
}
array[0] = num;
return 0;
}
int main()
{
int choice, num;
n = 0;
while(1)
{
printf("1.Insert the element \n");
printf("2.Delete the element \n");
printf("3.Display all elements \n");
printf("4.Quit \n");
printf("Enter your choice : ");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter the element to be inserted to the list : ");
scanf("%d", &num);
insert(num, n);
n = n + 1;
break;
case 2:
printf("Enter the elements to be deleted from the list: ");
scanf("%d", &num);
delete_elem(num);
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("Invalid choice \n");
}
}
}
void display()
{
int i;
if (n == 0)
{
printf("Heap is empty \n");
return;
}
for (i = 0; i < n; i++)
printf("%d ", array[i]);
printf("\n");
}
void delete_elem(int num)
{
int left, right, i, temp, parentnode;
for (i = 0; i < num; i++) {
if (num == array[i])
break;
}
if (num != array[i])
{
printf("%d not found in heap list\n", num);
return;
}
array[i] = array[n - 1];
n = n - 1;
parentnode =(i - 1) / 2;
if (array[i] > array[parentnode])
{
insert(array[i], i);
return;
}
left = 2 * i + 1;
right = 2 * i + 2;
while (right < n)
{
if (array[i] >= array[left] && array[i] >=
array[right])
return;
if (array[right] <= array[left])
{
temp = array[i];
array[i] = array[left];
array[left] = temp;
i = left;
}
else
{
temp = array[i];
array[i] = array[right];
array[right] = temp;
i = right;
}
left = 2 * i + 1;
right = 2 * i + 2;
}
if (left == n - 1 && array[i])
{
temp = array[i];
array[i] = array[left];
array[left] = temp;
}
}
In: Computer Science
C++
For this assignment, you will implement the MyString class. Like the string class in C++’s standard library, this class uses C-strings as the underlying data structure. Recall that a C-string is a null-terminated array of type char. See section 8.1 in Savitch for more information about C-strings; in particular, you will find it helpful to take advantage of several of the C-string functions mentioned in that section. What To Do. In the hw8 directory that is created, you will find the following files: • mystring.h and mystring.cpp • a Makefile • and 4 test files (test1.cpp through test4.cpp). (Below are the files mentioned here, with one sample file). Implement the following: 1. a default constructor 2. a constructor that takes a const char * parameter (that is, a C-string) 3. a destructor 4. a copy constructor 5. the assignment operator. In addition, overload the following relational operators: >, <, >=, <=, ==, and !=. Lastly, overload the operator+ (concatenation). All of the relational operators return type int. To understand why, read the description of the C-string function strcmp. All of the comparisons should be lexicographical, i.e., similar to what strcmp() does. The == and != operators should evaluate to 1 if the condition is true, 0 if false. You are welcome to implement some of the operators by using others (for example, you can easily implement != using ==). Make sure that you can invoke the operators with string literals on either side of the operator. That is, both of the following expressions should be valid: str == "hello" "hello" == str where str is a MyString object. Place the member function implementations in mystring.cpp and compile using make. You can also edit mystring.h if you wish to implement some of the member functions directly in the class definition
Make File:
CC = g++
CXX = g++
INCLUDES =
CFLAGS = -Wall $(INCLUDES)
CXXFLAGS = -Wall $(INCLUDES)
LDFLAGS =
LDLIBS =
executables = test1 test2 test3 test4
objects = mystring.o test1.o test2.o test3.o test4.o
.PHONY: default
default: $(executables)
$(executables): mystring.o
$(objects): mystring.h
.PHONY: clean
clean:
rm -f *~ a.out core $(objects) $(executables)
.PHONY: all
all: clean default
mystring.cpp:
#include
#include
#include "mystring.h"
// Insertion (put-to) operator
std::ostream& operator<<(std::ostream& outs, const MyString& s)
{
outs << s.data;
return outs;
}
// Extraction (get-from) operator
std::istream& operator>>(std::istream& is, MyString& s)
{
// Though this cheats a bit, it's meant to illustrate how this
// function can work.
std::string temp;
is >> temp;
delete[] s.data;
s.len = strlen(temp.c_str());
s.data = new char[s.len+1];
strcpy(s.data, temp.c_str());
return is;
}
mystring.h:
#ifndef _MYSTRING_H_
#define _MYSTRING_H_
#include
class MyString {
public:
// default constructor
MyString();
// constructor
MyString(const char* p);
// destructor
~MyString();
// copy constructor
MyString(const MyString& s);
// assignment operator
MyString& operator=(const MyString& s);
// returns the length of the string
int length() const { return len; }
// insertion (or put-to) operator
friend std::ostream& operator<<(std::ostream& outs, const MyString& s);
// extraction (or get-from) operator
friend std::istream& operator>>(std::istream& is, MyString& s);
// concatenates two strings
friend MyString operator+(const MyString& s1, const MyString& s2);
// relational operators
friend int operator<(const MyString& s1, const MyString& s2);
friend int operator>(const MyString& s1, const MyString& s2);
friend int operator==(const MyString& s1, const MyString& s2);
friend int operator!=(const MyString& s1, const MyString& s2);
friend int operator<=(const MyString& s1, const MyString& s2);
friend int operator>=(const MyString& s1, const MyString& s2);
private:
char* data;
int len;
};
#endif
Here is a sample test file:
#include "mystring.h"
static MyString add(MyString s1, MyString s2)
{
MyString temp(" and ");
return s1 + temp + s2;
}
int main()
{
using namespace std;
MyString s1("one");
MyString s2("two");
MyString s3 = add(s1, s2);
cout << s3 << endl;
return 0;
}
In: Computer Science
Explain two factors that may affect the IT project cost estimation using your own words. Support your answer with examples.
In: Computer Science
PLEASE I HAVE TO RETURN IN 20 MINUTES, I HAVE ALREADY DO THE QUESTION 1, 2, 3, 4 BUT THE QUESTION 5 I CAN'T
In python :
1)Write a sum function expecting an array of integers and returning its sum.
2) Write a multiply function excepting two arrays of integers and returning the product array term by term.
For example mutliply([1,2,3], [5,4,3]) will give [5,8,9]
3) Write a nb1 function expecting an array containing only 0 and 1 and returning the number of 1 present in the array.
4)Write a conFilter function expecting an integer n and creating an array of size n randomly filled with 0 and 1.
5) With these functions offer a random solution to the backpack problem. Here are some indications:
- The consFilter function allows you to construct an array retaining only one part of the objects to place in your backpack. So if the list of objects is [1,4,6,1] and the filter is [1,0,1,0], then by doing the product of the two you will get [1,0,6,0].
- You can generate a large number of random filters, for each of these filters to test if the objects thus filtered fit in the backpack. The rest comes down to a maximum calculation.
- You must make the best list of the weights of the objects fitting in the backpack. For example, if your backpack can hold 20kg, the list of items is [10, 1, 5, 8, 3, 9], one of the ways to optimize your bag is to put [10, 1, 3, 5] or 19kg.
Test on tables of 10-15 objects between 1 and 100kg each for a bag weight of 200 to 300kg.
In: Computer Science
Example: Consider a signal sampled at 1.2 kHz which is
composed of 50HZ, 90HZ and 150HZ of sine waves, having amplitudes
of 5V, 3V and 2V respectively .
Write a MATLAB program to plot signal in time domain as well as in
frequency domain to get information about major frequency
components present in the signal.
In: Computer Science
3. (Even or Odd) Write method IsEven that uses the remainder operator (%) to determine whether an integer is even. The method should take an integer argument and return true if the integer is even and false otherwise. Incorporate this method into an application that inputs a sequence of integers (one at time) and determines whether each is even or odd. (C# please)
In: Computer Science
Construct a PDA that matches all strings in the language over {x,y} such that each string has at least twice as many y's as x's.
Below, give a short description of the set of strings associated with each state of your PDA.
In: Computer Science