display list forwad and backward

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void printForward( IntSLLNode head) {
       if (head!=0) {
           cout<<(head->info);
           printForward( head->next );
       }
     }
}

     void  printBackward( IntSLLNode head ) {
       if (head != 0) {
           printBackward( head->next );
           cout<<(head->info);
       }
     }

}


Write one recursive function (a member function of class intSLList discussed in chapter 17)
which displays the contents of a linked list forward then backward. Write a test drive main
program which creates a list object of class intSLList and adds elements to the list and then the
list object should call your function once.

there is an error tells that "base operand of -> has non pointer type IntSLLNode" and another error said that no match for operators != in head !=0 what is that mean please any help?
It means that you have used a pointer indirection operator on a variable that isn't a pointer. Also, that the class or struct intSLList does not have a != operator but yet you have used one in your code.
how to combine these two function in one function how its will be? is it will work?
and how to test the function?
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
#include <iostream>
#include "list.h"
using namespace std;
void printFB( int el,IntSLLNode *ptr);


void printFB( int el,IntSLLNode *ptr) {
       if (el!=0)
           {cout<<(ptr->info);
           printFB( el,ptr->next );}
           else
           if (ptr!=0)
          {
            printFB( el,ptr->next );
           cout<<(ptr->info);
       }
     }

int main()
{
    int el;
    IntSLLNode *ptr;
    cout <<"please Enter an Element"<<endl;
    cin>>el;
    printFB (el,ptr);



    return 0;
}


something wrong with my code?
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
#include <iostream>
#include "list.h"
using namespace std;
void printFB( int el,IntSLLNode *ptr);


void printFB( int el,IntSLLNode *ptr) {
       if (el!=0)
           {cout<<(ptr->info);
           printFB( el,ptr->next );}
           else
           if (ptr!=0)
          {
            printFB( el,ptr->next );
           cout<<(ptr->info);
       }
     }

int main()
{
    int el;
    IntSLList L1;
    IntSLLNode *ptr;

   cout <<"please Enter an Element"<<endl;
    cin>>el;
    for(int i=0;i<10;i++)
        L1.addToTail(i);
    printFB (el,*ptr);

    return 0;
}


something wrong with the function call i guess m not really sure about how to test my function anyhelp?
Topic archived. No new replies allowed.