Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An anagram is a word or phrase formed by rearranging the letters of a different word or phrase. * Complete the methods to sort an

An anagram is a word or phrase formed by rearranging the letters of a different word or phrase. * Complete the methods to sort an array of strings so that all the anagrams are next to each other.

----Sample output---------- Before sort >> alert cares cautioned marine acres slaw education dear airmen awls asp auctioned ear later fairy tales races laws pas remain sap are dare read alter rail safety

After sort >> fairy tales rail safety

ONLY ADD CODE WHERE IT SAYS CODE HERE, DO NOT CHANGE ANY OTHER CODE PLEASE. WILL RATE SWIFTLY AND GENEROUSLY!

.cpp:

#include #include

using namespace std;

#define SIZE 25

string sortChar(string str) { int i, key, j; int n = str.length();

for (i = 0; i < n-1; i++) { for (j = 0; j < n-i-1; j++) { /* CODE HERE */ } } return str; }

void sortString(string strArray[]) { int i, j; for (i = 0; i < SIZE-1; i++){ /* CODE HERE */ for (j = 0; j < SIZE-i-1; j++){ /* CODE HERE */ } } }

void printStringArray(string strArray[]) { for (int i = 0; i < SIZE; i++) { cout << strArray[i] << endl; } }

int main() { string strArray[] = {"alert", "cares", "cautioned", "marine","acres", "slaw", "education", "dear", "airmen", "awls", "asp", "auctioned", "ear", "later", "fairy tales", "races", "laws", "pas", "remain", "sap", "are", "dare", "read", "alter", "rail safety"};

cout << "Before sort >> " << endl; printStringArray(strArray); cout << endl;

sortString(strArray);

cout << "After sort >> " << endl; printStringArray(strArray); cout << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions