How to print commas with linked list elements?

I'm trying to insert commas to separate the elements in a linked list.
(1000 should read 1,000, 219038210 should read 219,038,210 etc). I've tried counting up the number of elements in the linked list and modding by 3, but it does not work. I've read many times in the case of integers converting to a string to insert the commas, but I'm not sure how to do that in a linked list.

Here's what I have:
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
void LList::Print(){
        //PRE: The N.O. LList is valid
        //POST: The N.O. LList is unchanged, and its elements have been 
        //displayed

        Reverse();
        size=1;

        listnode*temp;
        temp=head;

        while(temp!=NULL){
                size++;
                if((size%3)==0)
                        cout<< temp->data <<"'";
                else
                        cout<<temp->data;

                temp=temp->next;
                }

        cout << endl <<endl;

        Reverse();

        }
closed account (D80DSL3A)
no reply.
Last edited on
i supports fun2code answer
Topic archived. No new replies allowed.