hi everyone
the program below is a function that should give the number of items greater than a number entered by a user.(unsorted list ADT)
ex:
input 3
unsorted list contains: 2 6 8 1 5 9 8
output should be 5

here is my try by there are alot of errors..could u plz help?

int GreaterThanItem(ItemType givenItem)
{
Node *ptr;
Ptr=head;
While(ptr!=node*)NULL)
{
If(ptr->info==item)
{
int Count_Max(node_ptr&q,int x)
{
    node_ptr p;
    p=q;
    int count=0;
    while(p!=NULL)
    {
        if(p->num > x)
        count++;
        p=p->next;
    }
    return count;
}
    }
Ptr=ptr->next;
}
Return NULL;
}

can anybody plz help?

What you're trying to do here:

If(ptr->info==item)
{
int Count_Max(node_ptr&q,int x)
{

is wrong. You can't declare a function inside another function.

Are your really using a linked list or did someone just give you that code?

i was trying..but the thing is that im weak at programming..
could u plz point me to my mistakes and help me remove the errors?

i was trying..but the thing is that im weak at programming..
could u plz point me to my mistakes and help me remove the errors?

He already has. You can't declare a function inside a function.

how can i solve this problem?
i should remove the function?
and then do what with the code that does the searching?

can you please help me write the main to the function so i can compile and run the program?

struct node{
int num;
node * next;
};
typedef node *node_ptr;

void firstNode(node_ptr &first,int n,char name[10])
{
if(first==NULL)
{


first=( node* )malloc(sizeof(node));
first->num=n;
first->next=NULL;
}
else
{
cout<<"Error:";
}
}

void append (node_ptr &first,int n,char name[10])
{

node_ptr p,q;

p=first;
while(p->next!=NULL)
{

p=p->next;
}
q=(node *)malloc(sizeof(node));
q->num=n;
q->next=NULL;
p->next =q;


}

void Display(node_ptr&q)
{
node_ptr p;
p=q;
while(p!=NULL)
{
p=p->next;
}
}

int Count_Max(node_ptr&q,int x)
{
node_ptr p;
p=q;
int count=0;
while(p!=NULL)
{
if(p->num > x)
count++;
p=p->next;
}
return count;
}

Please read this, so we can follow your code. It will also show you some problems you can fix yourself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.