Please help I need to write a problem that uses searching an
Please help! I need to write a problem that uses searching and sorting algorithm it’s like a short story! Then I would like to Translate the story into a FSM (finite state machine) after that you give Pseudocode for implementing the fsm.
Thanks!
Solution
Below is the code that includes the Searching and Sorting algorithm. The below code uses bubble sort technique to sort the inputs.
Psuedocode for below code:
Code:
#include <stdio.h>
#define MAXSIZE 10
void main()
{
int array[MAXSIZE];
int i, j, num, temp;
printf(\"Enter the value of num \ \");
scanf(\"%d\", &num);
printf(\"Enter the elements one by one \ \");
for (i = 0; i < num; i++)
{
scanf(\"%d\", &array[i]);
}
printf(\"Input array is \ \");
for (i = 0; i < num; i++)
{
printf(\"%d\ \", array[i]);
}
/* Bubble sorting begins */
for (i = 0; i < num; i++)
{
for (j = 0; j < (num - i - 1); j++)
{
if (array[j] > array[j + 1])
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
printf(\"Sorted array is...\ \");
for (i = 0; i < num; i++)
{
printf(\"%d\ \", array[i]);
}
