-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdd.cpp
89 lines (77 loc) · 1.29 KB
/
dd.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Sorting of dynamic array
#include<iostream>
using namespace std;
void ascending_order(int *array, int size);
void swap(int &a, int &b);
void fill_array(int *array, int &size);
int *increaseArray(int *array, int &size);
int main()
{
int i=1,j=1,k=1;
while (i <= 2) {
j=1;
while (j <= 3) {
k=2;
while(k <= 4)
{
cout<<("*");
k++;
}
cout<<("!");
j++;
}
cout<<endl;
i++;
}
}
void ascending_order(int *array, int size)
{
for (int i = 0; i < size; i++)
{
for(int j = i+1; j < size; j++)
{
if(array[i] > array[j])
{
swap(array[i], array[j]);
}
}
}
}
void swap(int &a, int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
void fill_array(int *array, int &size)
{
int index = 0;
char permission;
cout << "\nFill array as much as you want!!!";
do
{
if (index >= size)
{
array = increaseArray(array, size);
}
cout << "\nEnter number " << (index + 1) << ": ";
cin >> *(array + index);
cout << "\nDo you want to enter more (y/n)? ";
cin >> permission;
index++;
}
while(permission == 'y' || permission == 'Y');
}
int *increaseArray(int *array, int &size)
{
int new_size = size + 1;
int *newArray = new int[new_size];
for (int i = 0; i < size; i++)
{
newArray[i] = array[i];
}
delete [] array;
size = new_size;
return newArray;
}