Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- int Random(int alg)
- {
- int x = rand() % alg;
- return x;
- }
- void delFirstMetod(int* x,int n,int key)
- {
- clock_t start, stop;
- start = clock ();
- int i = 0;
- while (i < n) {
- if (x[i] == key) {
- for (int j = i; j<n-1; j++){
- x[j] = x[j+1];
- }
- n=n-1;
- }
- else {
- i = i+1;
- }
- }
- n = i;
- cout << n << ":";
- for (int k = 0; k < n; k++) {cout << x[k] << " ";}
- cout << endl;
- stop = clock();
- cout << stop - start << endl;
- }
- void delOtherMetod(int* x,int n,int key, int alg)
- {
- clock_t start, stop;
- start = clock ();
- int j = 0;
- for (int i = 0; i < n; i++) {
- x[j] = x[i];
- if ((x[i] != key)){
- j++;
- }
- }
- n = j;
- cout << n << ":";
- for (int k = 0; k < n; k++) {cout << x[k] << " ";}
- cout << endl;
- stop = clock();
- cout << stop - start;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int n, key, alg;
- cout << "Vvedite kolichestvo elements:" << endl;
- cin >> n;
- cout << "Vvedite diapozon randomizera:" << endl;
- cin >> alg;
- cout << "Vvedite key:" << endl;
- int* x = new int[n]; //{1,2,3,2,2,2,5,2,2,2};
- for (int i = 0; i<n; i++){
- x[i]=Random(alg);
- }
- cin >> key;
- delFirstMetod(x,n,key);
- delOtherMetod(x, n, key, alg);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement