#include "conio.h"#include "iostream"#include <stdio.h>#include <string>using namespace std; int FirstFunction(char *arr[], int num){ int j = 0; int MaxEl; char* a = arr[0]; while (a[j] != '\0'){ j++; } MaxEl = j; for (int i = 0; i < num;i++){ char* a = arr[i]; while (a[j] != '\0'){ j++; } if (j > MaxEl) { MaxEl = j; } j = 0; } return MaxEl;} char *SecondFunction(char *arr[], int num){ char *s1 = arr[0], *s2 = arr[1]; char* s3; char *temp; s3 = (char*)malloc(strlen(s1) + 1); strcpy(s3,s1); temp = s3; for (int i = 1; i < num;i++){ s1 = arr[i]; s3 = (char*)malloc(strlen(s1) + strlen(temp) + 2); strcpy(s3, temp); strcat(s3, " "); strcat(s3, s1); temp = s3; } return s3;} void strsort(char *arr[], int num){ for (int i = 0; i<num-1; i++) { int min = i; for (int j = i + 1; j<num; j++) { if (strcmp(arr[j], arr[min]) < 0) { min = j; } } char* dummy = arr[i]; arr[i] = arr[min]; arr[min] = dummy; } } int main(){ char *fruites[5] = { "apple", "banana", "orange", "apricot", "pineapple" }; cout <<"Lenght of largest element inlist : "<< FirstFunction(fruites, 5) << endl; cout << SecondFunction(fruites, 5) << endl; strsort(fruites, 5); cout << "Sorted array : " << endl; for (int i = 0; i < 5;i++) { cout << fruites[i] << endl; } _getch(); return 0; }
Comments