hi

I have been working in this code for a while and I need to know what's wrong with it ASAP.

here:

``````#include<iostream>
using namespace std;

class Node
{
public:
int value;
Node * next;
Node();
Node(int);
};
Node::Node():value(0),next(NULL){}
Node::Node(int v):value(v),next(NULL){}

bool AllPositive(next * h)
{
bool test = false;
Node* tmp;
{
{
test = true;
}
else
{
test = false;
exit if;
}

return test;
}
}

int Length(Node * h)
{
int count = 0;
while (current != NULL)
{
count++;
current = current->next;
}
return count;
}

bool Greater(Node * h1, Node * h2)
{

while (h1 != NULL && h2 != NULL)
{
h1 = h1 -> next;
h2 = h2 -> next;

}

int main()
{
Node * h = NULL;
bool positive = false;
Node* one = new Node(1);
Node* two = new Node(2);
Node* three = new Node(3);
h=one;
one->next=two;
two->next=three;

positive = AllPositive(h);
if (positive = true)
{
cout<<"all are positive";
}
else
{
cout<<"one or more negative";
}
Length( node* h);
Greater(Node * h1, Node * h2);

return 0;
}``````

The questions I'm trying to answer are those:

Q1: Write a function ‘AllPositive’ that takes the head of a linked list and returns true if all of the nodes in the linked list are positive, otherwise it returns false.
bool AllPositive(Node * h);

Q2: Write a function ‘Length’ that takes the head of a linked list as argument and returns the length of the list. Do NOT use recursion.
int Length(Node * h);

Q3: Write a function ‘Greater’ that takes the heads of two linked lists as arguments and returns true if the first linked list is greater than the second linked list. Otherwise it returns false. A linked list h1 is greater than the linked list h2 if h1 has more number of nodes than h2.
bool Greater(Node * h1, Node * h2);

Any help would be appreciated.

Edited by Nick Evan: Added CODE-tags

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by frogboy77

You may recieve more help if you clearly state your problem. i.e what do you expect your program to do and what is it doing wrong.
P.S USE CODE TAGS.

Post what errors you are getting. Also, indent the code using [ CODE ] tags, or just highlight the code with the option provided. Its hard to read unindented code.

It's OK I have found the problems with my code. And now it works fine.

Thank you guys for your kindness.

Then you should mark the thread as solved.