Created
March 22, 2017 15:36
-
-
Save Pan-Maciek/c890bfd1df36e86421018cb78b4c2fd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void join(char tab1[], char tab2[], char out[]) { | |
int i = 0, // indesk w tablisy out | |
i1 = 0, // indeks w tablicy 1 | |
i2 = 0; // indeks w tablicy 2 | |
while (true) { // powtarzanie kroków | |
if (tab1[i1] == '\0' && tab2[i2] == '\0') { // sprawdzamy koniec obu tablic | |
out[i] = '\0'; | |
return; // zakończenie funkcji | |
} | |
if (tab1[i1] < tab2[i2]) { // sprawdzamy który element jest większy krok (1a) | |
out[i++] = tab1[i1]; // krok (1b) kopiowanie do tablicy | |
if (tab1[i1] >= tab1[i1 + 1] && i2 > 0) // krok (1d) kopiowanie serii | |
while (tab2[i2 - 1] < tab2[i2]) // kopiowanie dopóki jesteśmy "w seri" | |
out[i++] = tab2[i2++]; | |
i1++; | |
} else { | |
out[i++] = tab2[i2]; // krok (1c) kopiowanie do tablicy | |
if (tab2[i2] >= tab2[i2 + 1] && i1 > 0) // krok (1d) kopiowanie serii | |
while (tab1[i1 - 1] < tab1[i1]) // kopiowanie dopóki jesteśmy "w seri" | |
out[i++] = tab1[i1++]; | |
i2++; | |
} | |
} | |
} | |
int main() { | |
char tab1[] = "aprtuefgzm"; | |
char tab2[] = "ndvkow"; | |
char tab3[50]; | |
join(tab1, tab2, tab3); | |
std::cout << tab3 << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment