Convert the Convergent-Pointer Algorithm pseudo code to C code. Use exact variables and make no modifications.
Hey,
Below is the answer to your question
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
int main()
{
int n;//define n
printf("Enter n: ");//print
scanf("%d",&n);// input n
printf("Enter n data items\n");
int data[n];
int i;
for(i=0;i<n;i++)
{
scanf("%d",&data[i]);////input data itemss
}
int legit=n,left=1,right=n;// define legit, left and right
while(left<right)// loop while left is less than right
{
if(data[left]!=0)// element at left is not 0
left=left+1;// increment left
else
{
legit--;// reduce legit by 1
data[left]=data[right];// copy right to left
right--;// reduce right by 1
}
}
if(data[left]==0)// if element at left is zero
legit--;// reduce legit by 1
return 0;
}
Kindly revert for any queries, will be waiting for your positive feedback.:)
Thanks.
Convert the Convergent-Pointer Algorithm pseudo code to C code. Use exact variables and make no modifications....
Question 1. Below is the pseudo code for a divide and conquer algorithm that finds the minimum value in an array. Suppose that the input array, A, is of size n, analyze the computational cost of this algorithm in the form of Tin) and prove your conclusion findMin (A, left, right) if (left == right) return Alleft) center - (left + right) / 2 return min (findMin (A, left, center), findMin (A, center + 1, right)
Title Algorithms Functional Requirements and Marks using c++ Write a pseudo-code algorithm for the following problems: Detect if three angles can make a triangle. (1) Hint: In a triangle, the sum of all angles is 180. Switch the value of two numbers (1) If a=2 and b=5, we want to have a=5 and b=2 at the end. Remember that a=b will result in the old value to of a to get lost. Receive a set of numbers and find...
The following gives the backtracking algorithm in pseudo-code for a constraint satisfaction problem, where U is a set of unassigned variables, and A is the current partial assignment search(U,A) if (U) return A; remove a variable X from U; for (each value a in X's domain) if (X-a is consistent with A) add X=a to A; res - search(U,A) if res !# false return res remove X=a from A; return false; A magic square of size N is an N...
/* FILE NAME: Class{aSet}.cpp FUNCTION: A template class for a set in C++. It implements all the set operations, except set compliment: For any two sets, S1 and S2 and an element, e A. Operations which result in a new set: (1) S1 + S2 is the union of S1 and S2 (2) S1 - S2 is the set difference of S1 and S2, S1 - S2 (3) S1 * S2 is the set intersection of S1 and S2, S1 * S2 (4) S1 + e (or e +...
:) Problem: ??? Your task: implement in CH the algorithm solution shown below. Then analyze it and explain, using just one or two sentences, what it does. Write this explanation as a comment at the top of your program. This explanation will be worth 5 points of your total grade. Do not be too detailed (for example, do not write it opens a file and then declares variables, and then reads from a file...), it should look like the problem...
Create a #define called MAPSIZE. Set to 10. Create global variables DirectionsFilename and MapFilename. Use char arrays and set them to nulls by using {}. Create a structure called RowCol that has two int members called row and col to hold the row and column. Function MoveNorth should have a return value of void and a parameter of a pointer to RowCol. { To move north, you need to subtract 1 from PositionPtr->row. Before doing so, you need to check...
Convert into pseudo-code for below code =============================== class Main { public static void main(String args[]) { Scanner s=new Scanner(System.in); ScoresCircularDoubleLL score=new ScoresCircularDoubleLL(); while(true) { System.out.println("1--->Enter a number\n-1--->exit"); System.out.print("Enter your choice:"); int choice=s.nextInt(); if(choice!=-1) { System.out.print("Enter the score:"); int number=s.nextInt(); GameEntry entry=new GameEntry(number); ...
Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...
C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the sortedList class. Call your new class doublyLinkedList. Convert the baseline code into a doubly linkedlist, and thoroughly test all existing operations (make sure to check all edge conditions), and then implement the new operations below. The class should have the following additional class methods: • A reverse method: this method will reverse the order of the doubly linked list. This method takes no parameters,...
Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...