-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathСортировка сравнений2.cpp
More file actions
62 lines (62 loc) · 946 Bytes
/
Copy pathСортировка сравнений2.cpp
File metadata and controls
62 lines (62 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;
struct Catridge
{
int key;
char value[10];
};
int main()
{
int i,j,n,*count;
Catridge *k,*s;
do
{
puts("Enter number of elements");
cin>>n;
}
while(n<=0);
k=new Catridge[n];
count=new int[n];
s=new Catridge[n];
for(i=0;i<n;i++)
{
cout<<"Enter key of element #"<<i+1<<"\n";
cin>>k[i].key;
cout<<"Enter value of element #"<<i+1<<"\n";
cin>>k[i].value;
count[i]=0;
}
for(i=n-1;i>=1;i--)
{
for(j=i-1;j>=0;j--)
{
if(k[i].key<k[j].key)
{
count[j]++;
}
else
{
count[i]++;
}
}
}
for(i=0;i<n;i++)
{
j=count[i];
s[j].key=k[i].key;
strcpy(s[j].value,k[i].value);
}
for(i=0;i<n;i++)
{
cout<<s[i].key<<"\t"<<s[i].value<<"\n";
}
delete[] k;
delete[] count;
delete[] s;
getch();
}