Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- struct Elem{
- int * key;
- Elem* link;
- Elem(){
- key = NULL;
- link = NULL;
- }
- };
- int main(){
- //P = new Elem();
- int n;
- cout << "vvedite kol-vo zapisey" << endl;
- cin >> n;
- Elem *R;
- R = new Elem[n];
- cout << "vvedite kolithestvo cifr v kazdom chisle" << endl;
- int t;
- cin >> t;
- cout << "vvedite kluchi" << endl;
- int a[n];
- for (int i = 0; i < n; ++i){
- cin >> a[i];
- a[i] = a[i] % (unsigned int)pow(10,t);
- R[i].key = new int[t];
- for (int j = 0; j < t; ++j){
- R[i].key[j] = a[i] % 10;
- // cout << endl << R[i].key[j];
- a[i] /= 10;
- }
- }
- Elem Top[10];
- Elem Botm[10];
- Elem *P = &R[n-1];
- int p = n-1;
- for (int k = 0; k < t; ++k){
- for (int i = 0; i < 10; ++i){
- Top[i].link = &Botm[i];
- Botm[i].link = NULL;
- }
- R3:
- int i = P->key[k];
- Top[i].link->link = P;
- Top[i].link = P;
- if(k==0 ){
- if(P!= NULL && p!=0){
- p--;
- P = &R[p];
- goto R3;
- }
- }else{
- P = P->link;
- if (P != NULL){
- goto R3;
- }
- }
- i = 0;
- H2:
- P = &Top[i];
- H3:
- i++;
- if(i==10){
- P->link = NULL;
- goto end;
- }
- if(Botm[i].link == NULL) goto H3;
- P->link->link = Botm[i].link;
- goto H2;
- end:
- P = Botm[0].link;
- }
- cout << "Sorted:\n";
- while(P){
- for(int i = t-1;i>=0;i--) cout << P->key[i];
- cout << endl;
- P = P->link;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement