Last change
on this file since 205 was 2, checked in by Rick van der Zwet, 15 years ago |
Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)
|
-
Property svn:executable
set to
*
|
File size:
1.2 KB
|
Rev | Line | |
---|
[2] | 1 | #include <iostream>
|
---|
| 2 | #include <ctime>
|
---|
| 3 | using namespace std;
|
---|
| 4 |
|
---|
| 5 | int randomgetal () { // tussen 0 en 999
|
---|
| 6 | static int getal = time (NULL) % 1000;
|
---|
| 7 | getal = ( 621 * getal + 1 ) % 1000;
|
---|
| 8 | return getal;
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | class listvak {
|
---|
| 13 | public:
|
---|
| 14 | int getal;
|
---|
| 15 | listvak * volgende_pt;
|
---|
| 16 | void random();
|
---|
| 17 | };
|
---|
| 18 |
|
---|
| 19 | //voeg een AantalGetallen_int getallen toe aan de List die door Lbgin wordt gepointerd.
|
---|
| 20 | void random(listvak * Lbegin) {
|
---|
| 21 | for (int i = 0; i < randomgetal(); i++) {
|
---|
| 22 | listvak * Lnew;
|
---|
| 23 | Lnew = new listvak;
|
---|
| 24 | Lnew->getal = randomgetal();
|
---|
| 25 | Lnew->volgende_pt = Lbegin->volgende_pt;
|
---|
| 26 | Lbegin->volgende_pt = Lnew;
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | //Vernietig de list gepointerd door Lbegin, laat enkel de verwijzing 'leven'
|
---|
| 31 | void destroy(listvak * Lbegin) {
|
---|
| 32 | listvak * hulp = Lbegin->volgende_pt;
|
---|
| 33 | while (hulp != NULL ) {
|
---|
| 34 | delete Lbegin->volgende_pt;
|
---|
| 35 | Lbegin->volgende_pt = hulp->volgende_pt;
|
---|
| 36 | hulp = Lbegin->volgende_pt;
|
---|
| 37 | }
|
---|
| 38 | Lbegin->getal = NULL;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | int main() {
|
---|
| 43 | listvak * L1;
|
---|
| 44 | listvak * L2;
|
---|
| 45 | listvak * L3;
|
---|
| 46 | L1 = new listvak;
|
---|
| 47 | L2 = new listvak;
|
---|
| 48 | L3 = new listvak;
|
---|
| 49 |
|
---|
| 50 | L1->getal = randomgetal();
|
---|
| 51 | L1->volgende_pt = NULL;
|
---|
| 52 | random(L1);
|
---|
| 53 | listvak * hulp = L1;
|
---|
| 54 | //lijst met vakjes uitlezen
|
---|
| 55 | while (hulp != NULL ) {
|
---|
| 56 | cout << hulp->getal << " ";
|
---|
| 57 | hulp = hulp->volgende_pt;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.