Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add postfix evaluation algorithm #890

Merged
merged 22 commits into from
Oct 25, 2021
Merged

feat: add postfix evaluation algorithm #890

merged 22 commits into from
Oct 25, 2021

Conversation

kumaryash18
Copy link
Member

@kumaryash18 kumaryash18 commented Oct 16, 2021

Description of Change

added postfix expression evaluation algorithm in misc

References

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • PR title follows semantic commit guidelines
  • I acknowledge that all my contributions will be made under the project's license.

Notes:
A program in C to evaluate postfix expression

@appgurueu
Copy link
Contributor

appgurueu commented Oct 17, 2021

Your arrays seem small to me (stack size of 10, input size of 25). Also consider using dynamic arrays. I find it quite odd that numbers can only be single characters - something like 45+3- first looks like 45 + 3 - instead of 4 5 + 3 - which it really is.

@kumaryash18
Copy link
Member Author

kumaryash18 commented Oct 17, 2021

Your arrays seem small to me (stack size of 10, input size of 25). Also consider using dynamic arrays. I find it quite odd that numbers can only be single characters - something like 45+3- first looks like 45 + 3 - instead of 4 5 + 3 - which it really is.

Hey
I will definitely try to look up in the array size. Reason to use single digit numbers was that it is easy to parse using isdigit() and having more than one digit will just make the expression ambiguous as pointed out. To fix this we can use a delimiter like , as in 45,+,3,-. But in this case parsing might be difficult. Any help is appreciated. @appgurueu

@Panquesito7 Panquesito7 added the enhancement New feature or request label Oct 17, 2021
Panquesito7
Panquesito7 previously approved these changes Oct 17, 2021
Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, this is looking awesome! 🚀 Thank you for your contribution! 😄👍
@appgurueu, feel free to review this PR and adjust as needed. Thanks. 🙂

@Panquesito7 Panquesito7 added the approved Approved; waiting for merge label Oct 17, 2021
@appgurueu
Copy link
Contributor

appgurueu commented Oct 17, 2021

To fix this we can use a delimiter like , as in 45,+,3,-. But in this case parsing might be difficult. Any help is appreciated. @appgurueu

Yes. I'd recommend a simple space as delimiter. You can do the following (in the loop) then:

// Ignore delimiter
if (post[i] == ' ') continue;
if (isdigit(post[i])) {
	int number = 0;
	do {
		number = number * 10 + (post[i]-'0');
		i++;
	} while (i < strlen(post) && isdigit(post[i]));
	push(number);
	continue;
}

@kumaryash18
Copy link
Member Author

kumaryash18 commented Oct 18, 2021

To fix this we can use a delimiter like , as in 45,+,3,-. But in this case parsing might be difficult. Any help is appreciated. @appgurueu

Yes. I'd recommend a simple space as delimiter. You can do the following (in the loop) then:

// Ignore delimiter
if (post[i] == ' ') continue;
if (isdigit(post[i])) {
	int number = 0;
	do {
		number = number * 10 + (post[i]-'0');
		i++;
	} while (i < strlen(post) && isdigit(post[i]));
	push(number);
	continue;
}

Hey
Thanks for your suggestion. I will try to make the required changes as soon as possible because I am busy with some python stuff. If it is possible, can you make the required commits?
Thanks @appgurueu

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, looks like your tests aren't made properly 👀 it also doesn't run when I try to run it.

image

Could you please fix those problems? Let us know if you need any help here or in our Discord server. 😃

misc/postfix_evaluation.c Outdated Show resolved Hide resolved
@kumaryash18
Copy link
Member Author

By the way, looks like your tests aren't made properly 👀 it also doesn't run when I try to run it.

image

Could you please fix those problems? Let us know if you need any help here or in our Discord server. 😃

Looks like this is a c++ compiler 👀 . In a C compiler it is working just fine.

misc/postfix_evaluation.c Outdated Show resolved Hide resolved
misc/postfix_evaluation.c Outdated Show resolved Hide resolved
Copy link
Member

@mishraabhinn mishraabhinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Work @kumaryash18

@ayaankhan98 ayaankhan98 merged commit 88a8299 into TheAlgorithms:master Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved; waiting for merge enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants