Uploaded by mudadon.333

Assignment#01

advertisement
Assignment#01
Instructions:
● You can help each other but do not copy assignment. In case of PLAGIARISM,
assignment of both the students will be marked as ZERO.
● Deadline for assignment submission is November 1, 2020 11:59 PM. NO ASSIGNMENT
WILL BE ACCEPTED AFTER DEADLINE.
● You have to submit the assignment in a zip folder renamed with your section & Roll# as
Sec A_Roll#1
1. Write a function named “find” that has the following prototype:
function find(data, target)
Data represents an array of integers, target integer value
The function will return true if target is one of the values in the array, and false otherwise.
You may not use any input or output statements in the function. Be sure to test your
function to see if it works.
2. Write a C++ function named “findInstances” that has the following prototype:
function findInstances(values, target)
Values represents an array of integers, target integer value
The function will return the number of entries in the array whose value corresponds to
the target. For example, the following code fragment uses the function you need to
define. a = [10, 20, 10, 10];
alert (findInstances(a, 10)); // this will display the value 3 because there are 3
copies of 10.
You may not use any input or output statements in the function. Be sure to test your
function to see if it works.
3. Write a function named “equals” that has the following
prototype: function equals(first, second)
The function has two integer arrays as parameters and returns true if the arrays have the
same values. For example, for:
first 10, 3, 7 and second 10, 3, 7 equals will return true
first 10, 7, 3 and second 10, 3, 7 equals will return false
first 10, 3, 7 and second 10, 3, 7, 8 equals will return false
You may not use any input or output statements in the function. Be sure to test your
function to see if it works!
4. Write a method that takes an array of int as an argument, plus two additional int
arguments called pos1 and pos2. The method should swap the elements of the array at
positions pos1 and pos2.
public static void swap(int [] arr, int pos1, int pos2)
5. Write a method that does one iteration of BubbleSort. It should use the swap method
you defined above. It should return true if it performed any swaps during the iteration,
and false otherwise.
public static Boolean bubbleSortIteration(int [] arr)
6. Consider a Telephone system that can store up to 10 numbers of most recent callers.
Once the system reaches the limit it deletes the number of least recent caller. Also the
system have an automatic redial feature that allows the user to redial the last number
automatically if he has lastly called the number himself, but if he ignored the number or
disconnects the number, the user can’t redial the number using the redial feature. Write
a code to design the same system using an appropriate data structure that allows the
user to:
i. Dial any number
ii. Redial any number
iii. Ignore/disconnect number
iv. Show the history of 10 called numbers from the most recent one to old.
7. Write a program that takes a word from the user and at the end shows that whether the
word is a palindrome or not. (Use stack to implement the program)
8. Write a program that reads in a sequence of characters, and determines whether all the
parentheses, braces, and curly braces are "balanced."
9. Write a program that reads in a positive integer and prints the binary representation of
that integer. (Use stack or queue to implement the program)
10. Implement a queue with two stacks.
11. Implement priority queue.
12. Convert the following infix expression to prefix expressions:
i. (a + b)*(c + d ) + e – f/g*h + 3.25
ii. (a + b – k + l) * (c + d) + e
iii. A + (((B – C) * (D – E) + F) / G) / (H – J)
13. Convert the following infix expression to postfix expressions:
i. ((((1^2)*3)–4) + ((5/6) / (7+8)))/2*2+1
ii. (A+B)*(C$(D–E) + F) – G
iii. (4+8)*(6–5+1) / ((3–2)*(2+2+3+1))
Download