help in function to return the number of items greater than certain number

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 50
Reputation: elsa87 is an unknown quantity at this point 
Solved Threads: 0
elsa87 elsa87 is offline Offline
Junior Poster in Training

help in function to return the number of items greater than certain number

 
0
  #1
Nov 18th, 2008
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?
  1. int GreaterThanItem(ItemType givenItem)
  2. {
  3. Node *ptr;
  4. Ptr=head;
  5. While(ptr!=node*)NULL)
  6. {
  7. If(ptr->info==item)
  8. {
  9. int Count_Max(node_ptr&q,int x)
  10. {
  11. node_ptr p;
  12. p=q;
  13. int count=0;
  14. while(p!=NULL)
  15. {
  16. if(p->num > x)
  17. count++;
  18. p=p->next;
  19. }
  20. return count;
  21. }
  22. }
  23. Ptr=ptr->next;
  24. }
  25. Return NULL;
  26. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 50
Reputation: elsa87 is an unknown quantity at this point 
Solved Threads: 0
elsa87 elsa87 is offline Offline
Junior Poster in Training

Re: help in function to return the number of items greater than certain number

 
0
  #2
Nov 18th, 2008
can anybody plz help?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,832
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: help in function to return the number of items greater than certain number

 
0
  #3
Nov 18th, 2008
What you're trying to do here:

  1. If(ptr->info==item)
  2. {
  3. int Count_Max(node_ptr&q,int x)
  4. {

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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 50
Reputation: elsa87 is an unknown quantity at this point 
Solved Threads: 0
elsa87 elsa87 is offline Offline
Junior Poster in Training

Re: help in function to return the number of items greater than certain number

 
0
  #4
Nov 18th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: Lokolo is an unknown quantity at this point 
Solved Threads: 1
Lokolo Lokolo is offline Offline
Light Poster

Re: help in function to return the number of items greater than certain number

 
0
  #5
Nov 18th, 2008
Originally Posted by elsa87 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 50
Reputation: elsa87 is an unknown quantity at this point 
Solved Threads: 0
elsa87 elsa87 is offline Offline
Junior Poster in Training

Re: help in function to return the number of items greater than certain number

 
0
  #6
Nov 18th, 2008
how can i solve this problem?
i should remove the function?
and then do what with the code that does the searching?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 50
Reputation: elsa87 is an unknown quantity at this point 
Solved Threads: 0
elsa87 elsa87 is offline Offline
Junior Poster in Training

Re: help in function to return the number of items greater than certain number

 
0
  #7
Nov 18th, 2008
can you please help me write the main to the function so i can compile and run the program?
  1. struct node{
  2. int num;
  3. node * next;
  4. };
  5. typedef node *node_ptr;
  6.  
  7. void firstNode(node_ptr &first,int n,char name[10])
  8. {
  9. if(first==NULL)
  10. {
  11.  
  12.  
  13. first=( node* )malloc(sizeof(node));
  14. first->num=n;
  15. first->next=NULL;
  16. }
  17. else
  18. {
  19. cout<<"Error:";
  20. }
  21. }
  22.  
  23. void append (node_ptr &first,int n,char name[10])
  24. {
  25.  
  26. node_ptr p,q;
  27.  
  28. p=first;
  29. while(p->next!=NULL)
  30. {
  31.  
  32. p=p->next;
  33. }
  34. q=(node *)malloc(sizeof(node));
  35. q->num=n;
  36. q->next=NULL;
  37. p->next =q;
  38.  
  39.  
  40. }
  41.  
  42. void Display(node_ptr&q)
  43. {
  44. node_ptr p;
  45. p=q;
  46. while(p!=NULL)
  47. {
  48. p=p->next;
  49. }
  50. }
  51.  
  52. int Count_Max(node_ptr&q,int x)
  53. {
  54. node_ptr p;
  55. p=q;
  56. int count=0;
  57. while(p!=NULL)
  58. {
  59. if(p->num > x)
  60. count++;
  61. p=p->next;
  62. }
  63. return count;
  64. }
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: help in function to return the number of items greater than certain number

 
0
  #8
Nov 18th, 2008
Please read this, so we can follow your code. It will also show you some problems you can fix yourself.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC