1 . Write a program in C or C++ to sort a set of integers. Use quicksort algorit
ID: 3818057 • Letter: 1
Question
1. Write a program in C or C++ to sort a set of integers. Use quicksort algorithm.
Input (from standard input: keyboard):
1. n – the number of integers to be sorted
2. n integers
Output: The n numbers sorted in increasing order.
Submit:
1. Your source code (the C/C++ program)
2. Screenshots of two sets of input and output (run your program twice). There must be at least 10 numbers in each set of input/output.
2. Write a program in C or C++ for binary search. First you need to sort a set of numbers (using the quicksort algorithm above). Then apply binary search.
Input (from standard input: keyboard):
1. n – the number of input integers
2. n integers
3. Two integers – these two integers are the keys. You need to search these two integers in the set of n numbers above.
Output: Output whether the two keys are in the set of n numbers.
Submit:
3. Your source code (the C/C++ program)
4. Screenshots of the input and output. n must be at least 10.
3. Write a program in C or C++ to implement a hash table with m = 13 and hash function: h(k) = k mod m
Initially store the following numbers in the hash table: 20, 75, 315, 101, 7, 545, 213, 67. Then perform the following sequence of insert and delete operations:
Delete: 213
Insert: 135
Delete: 20, 75, 7
Insert: 71
Delete: 135
Now search the following two numbers in the hash table: 135, 315. Then display the final content of the hash table.
Submit:
5. Your source code (the C/C++ program)
6. Screenshots of the output for: a) the search operations b) the final content of the hash table.
4. What are the differences between stacks and queues?
5. Write pseudocode for the enqueue and dequeue operations in a queue.
Explanation / Answer
1) #include<iostream.h>
#include<conio.h>
int a[100],l,u,i,j,n;
void quick(int *,int,int);
void main(){
clrscr();
cout <<"enter number of elements";
cin >> n;
cout <<"enter elements";
for(i=0;i<n;i++)
cin >> a[i];
l=0;
u=n-1;
quick(a,l,u);
cout <<"sorted elements";
for(i=0;i<n;i++)
cout << a[i] << " ";
getch();
}
void quick(int a[],int l,int u)
{
int p,temp;
if(l<u)
{
p=a[l];
i=l;
j=u;
while(i<j)
{
while(a[i] <= p && i<j )
i++;
while(a[j]>p && i<=j )
j--;
if(i<=j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;}
}
temp=a[j];
a[j]=a[l];
a[l]=temp;
cout <<" ";
for(i=0;i<n;i++)
cout <<a[i]<<" ";
quick(a,l,j-1);
quick(a,j+1,u);
}
}
OUTPUT
enter number of elements 10
enter elements5 2 3 16 25 1 20 7 8 61 14
1 2 3 5 25 16 20 7 8 61
1 2 3 5 25 16 20 7 8 61
1 2 3 5 25 16 20 7 8 61
1 2 3 5 25 16 20 7 8 61
1 2 3 5 25 16 20 7 8 61
1 2 3 5 8 16 20 7 25 61
1 2 3 5 7 8 20 16 25 61
1 2 3 5 7 8 16 20 25 61
1 2 3 5 7 8 16 20 25 61
sorted elements1 2 3 5 7 8 16 20 25 61
2) #include <stdio.h>
int main()
{
int c, first, last, middle, n, search, array[100];
printf("Enter number of elements "); // use the above prog to sort numbers in ascending order and incorporate in
// this program..
scanf("%d",&n);
printf("Enter %d integers ", n);
for (c = 0; c < n; c++)
scanf("%d",&array[c]);
How Many Elements:10
Enter 10 integers
12 39 40 68 77 78 80 82 85 89
Enter value to find:40
40 found at position 3
5) Enqueue and Dequeue operations in a queue:
Algorithm of isfull():
begin procedure isfull
if rear equals to MAXSIZE
return true
else
return false
endif
end procedure
Algorithm of isempty():
begin procedure isempty
if front is less than MIN OR front is greater than rear
return true
else
return false
endif end procedure
enqueue: procedure enqueue(data)
if queue is full
return overflow
endif rear rear + 1
queue[rear] data
return true
end procedure
dequeue: procedure dequeue
if queue is empty
return underflow
end if data = queue[front]
front front + 1
return true
end procedure
4. Differences between stacks and queues
STACK:
QUEUE:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.