-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructure_sorting.cpp
70 lines (51 loc) · 1.41 KB
/
structure_sorting.cpp
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
63
64
65
66
67
68
69
70
#include<bits/stdc++.h>
using namespace std;
typedef struct STUDENT{
char name[20];
int rollno;
int score;
};
int hash_num = 5381;
int n = 11;
STUDENT s[50];
void print_data(int n){
for(int i=0;i<n;i++){
cout<<"name: "<<s[i].name<<'\t';
cout<<"rollno: "<<s[i].rollno<<'\t';
cout<<"score: "<<s[i].score<<endl;
}
}
void generate_random_data(int n, int maxstrlen){
// generate random data
for(int i=n-1; i >= 0; i--){
for(int j=0; j<maxstrlen; j++){
s[i].name[j] = hash_num%26 + 'a';
// saving this character for later use in hash_num
char c = s[i].name[j];
hash_num = hash_num<<5 + hash_num + c;
hash_num%=26;
}
int temp1,temp2;
hash_num*=temp1;
hash_num%=26;
s[i].rollno = hash_num;
hash_num+=temp2;
hash_num%=26;
s[i].score = hash_num*4;
}
// still not complete
// for(int rollno=n; rollno >= 0; rollno--){
// for(int j=0; j<maxstrlen; j++){
// s[rollno].name[j] = hash_num%26 + 'a';
// // saving this character for later use in hash_num
// char c = s[rollno].name[j];
// hash_num = hash_num<<5 + hash_num + c;
// hash_num%=26;
// }
// }
}
int main(){
generate_random_data(n,3);
print_data(10);
return 0;
}