I am stuck on trying to get this recursive function's logic to make it work.
//Write a recursive function that returns true if the sequence of 0 < n integers in A is sorted in non-increasing order and false otherwise.
iostream and cmath libraries only
bool is_sorted(const int *A, unsigned int n){
if (n == 0) return false;
if (A > A+1) return true;
else return false;
}
bool is_sorted(const int *A, unsigned int n){
if (n == 1) return true;
if (*A < *(A+1)){
return false;
}
else{
return is_sorted(A+1, n-1);
}
}


I am stuck on trying to get this recursive function's logic to make it work. //Write...
I can not get this recursive binary search to wok for an edge case and it works but not for all, If you could look at it and try to find what is wrong to make this work for all edge cases. //Write a function that will return true if an element k is found in an array of integers A and false otherwise. The input to your //function is the array, its length 0 < n <= 10000, and...
How can I make this into a recursive function (C++)?? //Write a function that, given positive integers 1 <= n <= 10^4 and 1 <= s <= n as input, returns the sum of the last s elements in the sequence from 1 to n (inclusive). unsigned long int suffix_sum(unsigned int n, unsigned int s){ unsigned long int sum = 0,r=(n-s)+1; while (r<=n){ sum = sum + r; r++; } return sum; return 0; }
Can someone help me get this C program to work? I am trying to get a 2d array to work correctly. /* Deals a random hand of cards */ #include <stdio.h> #include <stdlib.h> #include <time.h> #define TRUE 1 #define FALSE 0 #define BOOL int #define NUM_SUITS 4 #define NUM_RANKS 13 int main() { BOOL in_hand[NUM_SUITS][NUM_RANKS] = {FALSE}; int num_cards = 13, rank, suit; const char rank_code[ 13 ][ 10 ] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}; const char suit_code[ 4 ] [ 10 ]...
////****what am i doing wrong? im trying to have this program with constructors convert inches to feet too I don't know what im doing wrong. (the program is suppose to take to sets of numbers feet and inches and compare them to see if they are equal , greater, less than, or not equal using operator overload #include <stdio.h> #include <string.h> #include <iostream> #include <iomanip> #include <cmath> using namespace std; //class declaration class FeetInches { private: int feet; ...
Can someone help with this C++ code. I am trying to compile and I keep running into these 4 errors. #include <iostream> #include <cassert> #include <string> using namespace std; typedef int fsm_state; typedef char fsm_input; bool is_final_state(fsm_state state) { return (state == 3) ? true : false; } fsm_state get_start_state(void) { return 0; } fsm_state move(fsm_state state, fsm_input input) { // our alphabet includes only 'a' and 'b' if (input != 'a' && input != 'b') assert(0); switch (state) {...
I am having trouble with my C++ program.... Directions: In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node), but it need not be sorted. The IntegerSet class should have two data fields: the cardinality (size) of the set, and the head reference to the...
Can anyone help me fix this program to make sure use stack and use STL library to check the name1 and name2 is palindrome. Thank you stackPalindrome.h #ifndef_STACK_PALINDROME_H #define_STACK_PALINDROME_H template <class StackPalindrome> class StackPalindrome { public: virtual bool isEmpty() const = 0; virtual bool push(const ItemType& newEntry) = 0; virtual bool pop() = 0; virtual ItemType peek() const = 0; }; #endif stack.cpp #include<iostream> #include<string> #include<new> #include "stackPalindrome.h" using namespace std; template <class ItemType> class OurStack...
Clojure member function question Hi, im trying to write recursive function in Clojure and am stuck The given scheme is : (define (member atm lizt) (cond ((null? lizt) #f) ((eq? atm (car lizt)) #t) (else (member atm (cdr lizt))) ) Can you translate that to Clojure member that is recursive?
I am trying to write a c++ program that will add two binary numbers that are entered into the command line. I cannot get the program to send anything to stdout. code attached. int main(int argc, char *argv[]) // IN IN { char partialSum[MAX_DIGITS + 1]; //partial sum of the binary numbers char sum[MAX_DIGITS + 1]; //sum of the binary numbers bool noError; //no error flag //Exit if insufficient arguments...
I am unsure how to add the following methods onto this code?? please help - rowValuesIncrease(int[][] t) A method that returns true if from left to right in any row, the integers are increasing, otherwise false. - columnValuesIncrease(int[][] t) A method that returns true if from top to bottom in any column, the integers are increasing, otherwise false. - isSetOf1toN(int[][] t) A method that returns true if the set of integers used is {1, 2, . . . , n}...