Question
Can you make this a function? Thank you.
int locationofMin(const string al, int n)i Return the position of a string in the array such that that string is <= every string in the array. If there is more than one such string, return the smallest position of such a string. Return-1 if the array has no elements. Heres an example: string people[5samwell, jonmargaery daenerystyrion int j = locationOfM in (people, 5); // returns 3, sincedaenerys is earliest // in alphabetic order ,
0 0
Add a comment Improve this question Transcribed image text
Answer #1

This is the function which is desired. It might be required to change a little based on how it is being called and used, so modify accordingly for accurate result.

static int locofMin(String[] a, int posi)
{
int pos=0;
String temp;
String[] arr1=a;
String[] arr2=a;

if(posi==0)
{
pos=posi;
  
}
else
{
for(int i=0;i<posi-1;i++)
{
for(int j=i+1;j<posi;j++)
{
if (arr1[i].compareTo(arr1[j])>0)
{
temp = arr1[i];
arr1[i] = arr1[j];
arr1[j] = temp;
}
}
}
  
for(int ak=0;ak<posi;ak++)
{
System.out.println("arr1 :"+arr1[ak]);
System.out.println("arr2 :"+arr2[ak]);
}
  
for(int i1=0;i1<posi-1;i1++)
{
for(int k1=0;k1<posi;k1++)
{
if(arr1[i1].equals( arr2[k1] ))
{
pos=k1;
System.out.println("arr1[i1] "+arr1[i1]+" arr2[k1]"+arr2[k1]);
break;
}
}
}
}

return pos;
}

Add a comment
Know the answer?
Add Answer to:
Can you make this a function? Thank you. int locationOfMin(const string a[], int n): Return the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help with this function i'm having trouble with: must be written in c++ All of...

    Please help with this function i'm having trouble with: must be written in c++ All of the functions you must write take at least two parameters: an array of strings, and the number of items the function will consider in the array, starting from the beginning. Your implementations must not use any global variables whose values may be changed during execution. Your program must build successfully under both Visual C++ and either clang++ or g++. Your program must not use...

  • Write function in C++: int removeDups (string a[], int n); For every sequence of consecutive identical...

    Write function in C++: int removeDups (string a[], int n); For every sequence of consecutive identical items in a, retain only one item of that sequence. Suppose we call the number of retained items r. Then when this function returns, elements through of a must contain the retained items (in the same relative order they were in originally), and the remaining elements may have whatever values you want. Return the number of retained items. Here's an example: string [9] =...

  • Please help with this function i'm having trouble with: must be written in c++ All of...

    Please help with this function i'm having trouble with: must be written in c++ All of the functions you must write take at least two parameters: an array of strings, and the number of items the function will consider in the array, starting from the beginning. Your implementations must not use any global variables whose values may be changed during execution. Your program must build successfully under both Visual C++ and either clang++ or g++. Your program must not use...

  • Need help with these array problems. int countAllPunctuation( const string array[ ], int n ); Return...

    Need help with these array problems. int countAllPunctuation( const string array[ ], int n ); Return the total number of punctuation symbols found in all the elements of the passed array argument. For the purpose of this function, the characters '.' , ',', '!', ';', ''', '-', '/', ':', '?', '"' count as punctuation symbols (that is, period, comma, exclamation mark, semicolon, apostrophe, dash, slash, colon, question mark, and double quote). Return -1 if n <= 0. For example, for...

  • C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the...

    C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable n will be greater than or equal to zero. Example: string array[6] = { "a", "b", "", "c", "d", "e" }; int q = flip(array, 4); // returns 4 // array now contains: "c" "" "b" "a" "d" "e" Write a function, int flip(string a[], int n); It reverses the order of the elements of...

  • How do I do this? -> string print() const; Function to output the data, return the...

    How do I do this? -> string print() const; Function to output the data, return the output in the form of string, with all elements in the hash table included and each seperated by a space this is my code: template <class elemType> string hashT<elemType>::print() const { for (int i = 0; i < HTSize; i++){        if (indexStatusList[i] == 1){        cout <<HTable[i]<< " " << endl;        }   }    } **********Rest of the code...

  • C++ language Write a function, int flip(string a[], int n); It reverses the order of the...

    C++ language Write a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable n will be greater than or equal to zero. Example: string array[6] = { "a", "b", "", "c", "d", "e" }; int q = flip(array, 4); // returns 4 // array now contains: "C" "" "" "a" "d" "e" O Full Screen 1 code.cpp + New #include <string> 2 using namespace std; 3 4- int...

  • Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the...

    Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the index of the largest element in the given sequence that is less than the given value. If multiple elements satisfy, return the one with smallest index. Return -1 if no such element exists. //main.cpp #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; #include "source.h" struct Point{    int x,y;    bool operator<(const Point& p) {        return (x<p.x || (x==p.x&&y<p.y));    } }; int...

  • //codes in DynamicString.cpp #include "DynamicString.h" int DynamicString::myStringLen(const char* str){ //TODO::Implement me return -1; } DynamicString::DynamicString(){ //TODO::1::Implement...

    //codes in DynamicString.cpp #include "DynamicString.h" int DynamicString::myStringLen(const char* str){ //TODO::Implement me return -1; } DynamicString::DynamicString(){ //TODO::1::Implement me } DynamicString::DynamicString(const char* str){ //TODO::1::Implement me } int DynamicString::len() const{ //TODO::1::Implement me return -1; } const char* DynamicString::c_str() const{ //TODO::1::Implement me return nullptr; } char& DynamicString::char_at(int position){ //TODO::1::Implement me char* a = new char('a'); return *a; } char DynamicString::char_at(int position) const{ //TODO::1::Implement me return 'a'; } char& DynamicString::operator[](int position){ //TODO::1::Implement me char* a = new char('a'); return *a; } char DynamicString::operator[](int position) const{...

  • Write a function getScores(...) that is given a string, an int type array to fill and...

    Write a function getScores(...) that is given a string, an int type array to fill and the max number of elements in the array as parameters and returns an integer result. The function will find each substring of the given string separated by space characters and place it in the array. The function returns the number of integers extracted. For example: int values[3]; getScores("123 456 789", values, 3 ); would return the count of 3 and fill the array with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT