Recursive function help!
May 7, 2013 at 4:51am UTC
Im stuck. Im having trouble making the linked list print all 'Z' if the elements in the list are capital. void make_Zs can only pass a parameter that is a pointer to the list.
make_Zs needs to be called inside its definition to "loop" through the list and change the capital letters to Zs
I keep getting invalid conversion from char to list_node?
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
#include <cstdlib>
#include <iostream>
using namespace std;
struct list_node
{
char stuff;
list_node* next;
};
typedef list_node* list_ptr;
void build (list_ptr& front, int nodes, char ch);
void print (list_ptr front);
void sub1_skip (list_ptr front);
void make_Zs (list_ptr front);
int main(int argc, char *argv[])
{
list_ptr front, skip;
build (front, 5, 'A' );
sub1_skip (front);
make_Zs (front);
cout << "\nThe list is:\n" ;
print (front);
cout << "\n\n" ;
system("PAUSE" );
return EXIT_SUCCESS;
}
void build (list_ptr& front, int nodes, char ch)
{
if (nodes == 0)
front = NULL;
else
{
front = new list_node;
front -> stuff = ch;
build (front -> next, nodes - 1, ch + 1);
}
}
void sub1_skip (list_ptr stuff)
{
}
void make_Zs (list_ptr front)
{
if (front -> stuff >= 65 && front -> stuff <= 90)
{
front -> stuff = 'Z' ;
make_Zs (front -> );
}
}
void print (list_ptr front)
{
if (front != NULL)
{
cout << front -> stuff << " " ;
print (front -> next);
}
}
May 7, 2013 at 11:05pm UTC
This
void sub1_skip (list_ptr front);
and this
void sub1_skip (list_ptr stuff)
are different. I know your not at that point yet, but thought i should point that out.
May 7, 2013 at 11:29pm UTC
In what way are they different Myangryplatypus ?
Topic archived. No new replies allowed.