1. Hi everyone! I am here again. I need your help. Actually i have a problem in linked lists. The exercise says to make a program with linked lists which will tell the user if an equation is true or false, and by true or false i mean that the program must check if the precedence of operations is true or false. For example when the user puts this : (a+10)*((c+d)/(x-5))) + (7*3) the program will say it's true and if he puts this : (a+10)*((c+d)/(x-5))) + 7*3) the program will say it's wrong. The exercise must be done with linked lists. Does anyone knows how i am supposed to start it??? I know a way but i can't make my program work. I appreciate every small tip.

2. Originally Posted by ValL
The exercise says to make a program with linked lists which will tell the user if an equation is true or false, and by true or false i mean that the program must check if the precedence of operations is true or false.
I don't understand that part. How can the precedence be true or false? The precedence of an operation is defined somewhere, thus it is always true.

Originally Posted by ValL
For example when the user puts this : (a+10)*((c+d)/(x-5))) + (7*3) the program will say it's true and if he puts this : (a+10)*((c+d)/(x-5))) + 7*3) the program will say it's wrong.
IMHO both examples are wrong because both have mismatching parentheses.

I find your description confusing.

Bye, Andreas

3. I mean if the user forget to put a parenthesis then the equation will be false... i mean this (a+10)*((c+d)/(x-5))) + (7*3) is different from this (a+10)*((c+d)/(x-5))) + 7*3)

4. Originally Posted by ValL
I mean if the user forget to put a parenthesis then the equation will be false... i mean this (a+10)*((c+d)/(x-5))) + (7*3) is different from this (a+10)*((c+d)/(x-5))) + 7*3)
But both are still wrong.

You could add a node for each opening parenthesis and remove a node for each closing one, i.e. implement a stack with a linked list.
If the list is empty after reading the expression, it's ok.

Bye, Andreas

5. mmm i think you are right but the teachers in the exercise the give it like told you before. Maybe they forgot a parenthesis in the beginning of the first equation. Thanks by the way for your help!!

6. Let me ask you something more. First the user gives the equation, then if the parenthesis is ( it puts it in the list and if the parenthesis is ) it removes it from the list. But the think i do not understand is how the program will choose to take only the parenthesis and check them and not the numbers and the symbols from the equation?

7. Originally Posted by ValL
Let me ask you something more. First the user gives the equation, then if the parenthesis is ( it puts it in the list and if the parenthesis is ) it removes it from the list. But the think i do not understand is how the program will choose to take only the parenthesis and check them and not the numbers and the symbols from the equation?
why not use a stack?

8. I don't know because the teachers said, make the exercise with linked lists Is it difficult to make it work with lists??

9. Does anyone Knows how and where to download matlab?? I need it for an exercise in school and i can't find it anywhere :/

10. Originally Posted by ValL
Does anyone Knows how and where to download matlab?? I need it for an exercise in school and i can't find it anywhere :/
The student version of Matlab costs \$100.00 in the USA; asking to get a illegal copy might violate this site rules.

Tim S.

11. Ok and sorry i didn't know that. By the way can someone tell me how i can make the above work? I tried it many times but nothing. I mean how the program will know how to choose only the parenthesis and put them in the linked list and not the numbers and the symbols??

12. Scilab and Octave are open source alternatives to Matlab.

Octave is closer to being a Matlab Clone.
GNU Octave - Wikipedia, the free encyclopedia

FreeMat is something I just found out about; no idea how it compares to the other two.
http://en.wikipedia.org/wiki/FreeMat

Can't really help with the programming question; it is not something I can understand today.

Tim S.

13. Originally Posted by ValL
By the way can someone tell me how i can make the above work? I tried it many times but nothing. I mean how the program will know how to choose only the parenthesis and put them in the linked list and not the numbers and the symbols??
I guess you get the equation from the user as a string, right?

So just walk through the string character by character and when you come across an opening parenthesis add it to your list and if you come across a closing parenthesis remove the open parenthesis from the list.

Can you show us the code you have tried?

Bye, Andreas

14. Hi again!! Here is what i have tried so far... I sent it as you told me and i please want to tell me if you can where are my mistakes and explain them to try and fix them.

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node
{
char Data;
struct Node *Next;

void insert(char equation) //start of insert function
{
int length = strlen(equation); //Here i am trying to find the length of the equation, so i don't know if is the wright way to put it
int i;
struct Node *new_node, *old_node;

new_node = (struct Node *)malloc(sizeof(struct Node));

for(i=0; i<length; i++)
{
if(equation == '(' )
{
new_node->Data=equation;
}
else if(equation == ')' )
{
Delete();
}
}

{
printf("The equation is correct");
printf("\n");
}
else
{
printf("The equation is not correct");
printf("\n");
while(old_node->Next != NULL)
old_node = old_node->Next;

new_node->Next = NULL;
old_node->Next = new_node;
}
I know that if the list is empty i have to tell to user that the equation is correct and if the list is not empty that the equation is not correct but i don't know if i only have to print that messages or continue to the next node too.
}

void Delete()//start of delete function i don't know here if my function is correct or is false so i need your help suriously...
{
struct Node *last;
last = (struct Node *)malloc(sizeof(struct Node));

struct Node *previous_last;
previous_last = (struct Node *)malloc(sizeof (struct Node));

while(last->Next != NULL)
{
previous_last = last;
last = previous_last->Next;
}
previous_last->Next = NULL;
free(last);
printf("The element has been deleted \n");
printf("\n");

}

int main()
{
char eq;

printf("Please give an equation: ");
scanf("%s", &eq);
printf("\n");
insert(eq);

return 0;
system ("pause");
}```
Thanx for your understanding

15. Anyone????

Popular pages Recent additions