| | |
help in function to return the number of items greater than certain number
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 50
Reputation:
Solved Threads: 0
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?
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?
C++ Syntax (Toggle Plain Text)
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; }
What you're trying to do here:
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?
C++ Syntax (Toggle Plain Text)
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?
•
•
Join Date: Oct 2008
Posts: 50
Reputation:
Solved Threads: 0
can you please help me write the main to the function so i can compile and run the program?
C++ Syntax (Toggle Plain Text)
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- Please help me to convert a simple C++ program into an object-oriented one. (C++)
- Prime Number (Help Plz!) (VB.NET)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Need help with strings in C programming (C)
- Here is the doc file for the assignment (C++)
- Unsorted List ADT Client Code Help (C++)
- I lack focus... (Java)
Other Threads in the C++ Forum
- Previous Thread: char arrays and strcpy trouble
- Next Thread: Linklist can't show its element
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






