Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable operator for comparison

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Alright, hopefully this will be easy. I'm creating an integer heap (for a priority queue). However, I do not know if it's a high-num high-pri or a low-num high-pri until the user tells me so. Is there a way to interpret a char variable as an operator? Say, for example, char top_op = '<'; is there some way I could test
if(heap_array[2*n+1] **some function of top_op** heap_array[2*n+2]) ?
Thanks for any help.

sjm
 
Hi

I personally would use a switch statement on the user input then perform the necessary operation.

switch(top_op)
{
case '<':
.
.
break;
.
.
}

I think this makes your code much more readable and you can also validate the user input alot easier (using default: in the switch statement).

I don't know anyway of implementing it in the way you mentioned.

Hope that helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top