Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Napisz funkcję scalającą w jeden ciąg wynikowy dwa posortowane niemalejąco ciągi o długościach
- odpowiednio N i M, z zachowaniem uporządkowania i stabilnie. Implementacja optymalna. */
- #include <iostream>
- #include <string>
- using namespace std;
- int const size_1 = 5;
- int const size_2 = 6;
- void sort_babelkowe(string *tab,int size)
- {
- for(int i =0; i<size;i++)
- {
- for(int j =0; j<size -1;j++)
- {
- if (tab[j]>tab[j+1])
- swap(tab[j],tab[j+1]);
- }
- }
- }
- void show (string * tab,int size)
- {
- for(int i =0;i<size;i++)
- cout<<tab[i]<<" ";
- cout<<endl;
- }
- void merge(string *tab1,string *tab2,int size1,int size2,string *tab3)
- {
- for(int i = 0;i<size1;i++)
- {
- tab3[i]=tab1[i];
- }
- int j =0;
- for(int i = size1;i<size1+size2;i++)
- {
- tab3[i] =tab2[j];
- j++;
- }
- }
- int main()
- {
- string tab_1[] = {"augustowski","katowicki","krakowski","nyski","opolski" };
- string tab_2[] = {"krakowski","lubelski","opolski","poznanski","radomski","wroclawski"};
- string tab_3[size_1+size_2];
- sort_babelkowe(tab_1,size_1);
- cout<<"Posortowana 1 tablica:"<<endl;
- show(tab_1,size_1);
- cout<<"Posortowana 2 tablica:"<<endl;
- sort_babelkowe(tab_2,size_2);
- show(tab_2,size_2);
- cout<<"Scalanie"<<endl;
- merge(tab_1,tab_2,size_1,size_2,tab_3);
- show(tab_3,size_1+size_2);
- cout<<"sortowanie"<<endl;
- sort_babelkowe(tab_3,size_1+size_2);
- show(tab_3,size_1+size_2);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment