Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <cstring>
- using namespace std;
- bool fjakriterija(char *a, char *b)
- {
- return std::strcmp(a,b)<0;
- }
- int main(){
- int n;
- cout << "Koliko recenica zelite unijeti: ";
- cin >> n;
- cin.ignore(10000,'\n');
- char **niz(nullptr);
- try{
- niz = new char*[n];
- for(int i = 0; i < n; i++)
- niz[i] = nullptr;
- string temp;
- for(int i = 0; i < n; i++){
- getline(cin, temp);
- niz[i] = new char[temp.length()+1];
- *copy(temp.begin(), temp.end(), niz[i]) = '\0';
- }
- std::sort (niz, niz+n, fjakriterija);
- for(int i = 0; i< n; i++){
- cout << i << ": " << niz[i] << endl;
- }
- for(int i = 0; i < n; i++)
- delete[] niz[i];
- delete[] niz;
- niz = nullptr;
- }catch(bad_alloc){
- if(niz != nullptr){
- for(int i = 0; i < n; i++)
- delete[] niz[i];
- delete[] niz;
- }
- cout << "Doslo je do greske s memorijom. Hvala!";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement