Passing a list

Quick question... how do you pass a list in to a function...

For example forvoid reverseListwhat would the parameters be
for my function... I'm trying to put everything in my case R statement in
a function so I can make a neat class...

Thanks.

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
#include <iostream>
#include <list>
#include <cstdlib>
#include <conio.h>

using namespace std;

void reverseList();
void sortList();
void removeData();
void clearData();
char getPick();

int main(){

    list<double> numbers; // declares the list
    list<double>::iterator ip;

    bool run = true;

    cout << "============List Program(v2)===========\n" << endl;

    for(int i = 1; i < 11; i++) numbers.push_back(i*10);

    cout << "The original list:";
    for(ip = numbers.begin(); ip != numbers.end(); ip++) // outputs list contents
         cout << ' ' << *ip;

    do{
        switch(getPick()){

            case 'R':{system("cls"); // reversing the list
                      numbers.reverse();

                      cout << "List reversed:";
                      for(ip = numbers.begin(); ip != numbers.end(); ip++)
                           cout << ' ' << *ip;
                     }break;

            case 'S':{system("cls"); // sorting the list
                      numbers.sort();

                      cout << "List sorted:";
                      for(ip = numbers.begin(); ip != numbers.end(); ip++)
                          cout << ' ' << *ip;
                     }break;

            case 'D':{system("cls"); // removing numbers from the list
                      int n;
                      double num;

                      cout << "Current list:";
                      for(ip = numbers.begin(); ip != numbers.end(); ip++)
                          cout << ' ' << *ip;

                      cout << "\n\nHow many numbers do you want to delete: "; cin >> n;

                      if(n < 2)
                        cout << "What number do you want deleted:\n";
                      else
                        cout << "What numbers do you want deleted:\n";

                      for(int i = 0; i < n; i++){
                          cin >> num;
                          numbers.remove(num);
                      }

                      system("cls");
                      cout << "The list has the numbers:";
                      for(ip = numbers.begin(); ip != numbers.end(); ip++)
                           cout << ' ' << *ip;
                     }break;

            case 'C':{system("cls"); // clearing & adding to the list
                      int l;
                      double num;

                      numbers.clear();

                      cout << "How many numbers do you want to add: "; cin >> l;
                      cout << "Enter new number(s):\n";

                      for(int i = 0; i < l; i++){
                           cin >> num;
                           numbers.push_back(num); // starts from first digit entered
                         //numbers.push_front(num); // starts from the last digit entered
                      }

                      system("cls");
                      cout << "The list now contains:";
                      for(ip = numbers.begin(); ip != numbers.end(); ip++)
                           cout << ' ' << *ip;
                     }break;

            case 'E':{system("cls"); // checking to see if the list is empty
                      double sum(0);

                      while (!numbers.empty()){
                        sum += numbers.front();
                        numbers.pop_front();
                      }

                      cout << "Total: " << sum << endl;
                     }break;

            case 'Q': run = false; break;

            default: cout << "That's not a valid choice!" << endl; break;
        }
    }while(run);

    system("cls");
    cout << "\nAu revoir!!!" << endl;

    return 0;
}

char getPick(){ // user picks how to manipulate the list

    char pick;

    cout << "\n\nWhat would you like to do?";
    cout << "\n(R)everse, (S)ort, (D)elete, (C)lear, (E)mpty, (Q)uit" << endl;

    pick = getch();

    return toupper(pick);
}

I'm sure you just pass the address of the list, just like you would do with vectors or arrays.

void ReverseList(List&)

in main

ReverseList(myList)
yea thanks bro...
Topic archived. No new replies allowed.