-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
206 lines (206 loc) · 4.82 KB
/
Source.cpp
File metadata and controls
206 lines (206 loc) · 4.82 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//#include<iostream>
//#include <math.h>
//#include <vector>
//
//using namespace std;
////
////float invSqrt(float x)
////{
//// float xhalf = 0.5f*x;
//// union
//// {
//// float x;
//// int i;
//// } u;
//// u.x = x;
//// u.i = 1597463007 - (u.i >> 1);
//// /* The next line can be repeated any number of times to increase accuracy */
//// u.x = u.x * (1.5f - xhalf * u.x * u.x);
//// u.x = u.x * (1.5f - xhalf * u.x * u.x);
//// u.x = u.x * (1.5f - xhalf * u.x * u.x);
//// return 1 / u.x;
////}
////
////float sqrt_approx(float z)
////{
//// int val_int = *(int*)&z; /* Same bits, but as an int */
//// /*
//// * To justify the following code, prove that
//// *
//// * ((((val_int / 2^m) - b) / 2) + b) * 2^m = ((val_int - 2^m) / 2) + ((b + 1) / 2) * 2^m)
//// *
//// * where
//// *
//// * b = exponent bias
//// * m = number of mantissa bits
//// *
//// * .
//// */
////
//// val_int -= 1 << 23; /* Subtract 2^m. */
//// val_int >>= 1; /* Divide by 2. */
//// val_int += 1 << 29; /* Add ((b + 1) / 2) * 2^m. */
////
//// return *(float*)&val_int; /* Interpret again as float */
////}
////
////double sqrt_local(double x) {
//// if (x <= 0)
//// return 0; // if negative number throw an exception?
//// int exp = 0;
//// x = frexp(x, &exp); // extract binary exponent from x
//// if (exp & 1) { // we want exponent to be even
//// exp--;
//// x *= 2;
//// }
//// double y = (1 + x) / 2; // first approximation
//// double z = 0;
//// while (y != z) { // yes, we CAN compare doubles here!
//// z = y;
//// y = (y + x / y) / 2;
//// }
//// return ldexp(y, exp / 2); // multiply answer by 2^(exp/2)
////}
////
////double desi_function_sqrt(double val, int decimal_places=5) {
////
//// double rand_number = rand() % (int)val + 1;
//// double intial_num = rand_number - (rand_number * rand_number - val)/(2*rand_number);
////
//// if (intial_num == 0)
//// return rand_number;
//// double next_num = 0;
//// while (decimal_places >0) {
//// next_num = intial_num - (intial_num * intial_num - val)/ (2* intial_num);
//// if (next_num == 0)
//// break;
//// decimal_places--;
//// intial_num = next_num;
////
////
//// }
//// return intial_num;
////
////}
////
////#include <stack>
////
////bool isValid(string s) {
//// stack< char > mystack;
////
//// if (s.length() % 2 != 0)
//// return false;
////
//// for (int i = 0; i < s.length(); i++) {
//// if (s[i] == '(' || s[i] == '{' || s[i] == '[') {
//// mystack.push(s[i]);
//// }
//// else {
//// if (mystack.empty())
//// return false;
//// char test = mystack.top();
//// mystack.pop();
////
//// if (s[i] == ')') {
//// if (test == '(')
//// continue;
//// else
//// return false;
//// }
//// if (s[i] == '}') {
//// if (test == '{')
//// continue;
//// else
//// return false;
//// }
//// if (s[i] == ']') {
//// if (test == '[')
//// continue;
//// else
//// return false;
//// }
//// }
//// }
////
//// if (mystack.empty())
//// return true;
//// else
//// return false;
////
////}
////struct ListNode {
//// int val;
//// ListNode *next;
//// ListNode(int x) : val(x), next(NULL) {}
////
////};
////ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
//// struct ListNode* newlist;
//// struct ListNode* tail = newlist;
//// newlist->next = NULL;
////
//// if (l1 == NULL) return l2;
//// if (l2 == NULL) return l1;
////
//// while (l1 != NULL && l2 != NULL) {
//// if (l1->val <= l2->val) {
//// struct ListNode temp(l1->val);
//// tail->next = &temp;
//// tail = tail->next;
//// l1 = l1->next;
//// }
//// else {
//// struct ListNode temp(l2->val);
//// tail->next = &temp;
//// tail = tail->next;
//// l2 = l2->next;
////
//// }
////
//// }
//// while (l1 != NULL) {
//// struct ListNode temp(l1->val);
//// tail->next = &temp;
//// tail = tail->next;
//// l1 = l1->next;
////
//// }
//// while (l2 != NULL) {
//// struct ListNode temp(l2->val);
//// tail->next = &temp;
//// tail = tail->next;
//// l2 = l2->next;
//// }
////
//// return newlist;
////
////}
////ListNode* mergeKLists(vector<ListNode*>& lists) {
////
//// if (lists.size() == 0) return NULL;
//// int n = lists.size() - 1;
////
//// while (n > 0) {
//// for (int i = 0; i < (n + 1) / 2; i++) {
//// lists[i] = mergeTwoLists(lists[0], lists[n - i]);
//// }
//// n /= 2;
//// }
////
//// return lists[0];
////
////}
//int voimain() {
// //cout << isValid("))}}]]{[([}}[}[(([[]]([}(}}[[[]{){[)") << endl;
// //cout << isValid("()") << endl
// //vector <ListNode *> list;
//
//
// vector < vector <int, int> > temp_vect;
//
//
//
// //cout << mergeKLists();
//
// return 0;
//}