+ 3

Can someone help me with an adapted algorithm?

I work on a program that make the addition of two polynomials with linked list. Our tutor says he wants the user to enter the whole polynomial at once instead of entering the coefficients and degrees successively! I am working with linked lists and I have a function which adds monomials to form a polynomial through a linked list (ie: function addmonome(Poly p, coef, deg)). If you want some code , tells me!

13th Jan 2022, 3:05 PM
Romaric
16 Answers
+ 1
Romaric Would you mind posting your progress here? I mean, the code upto now.
13th Jan 2022, 4:46 PM
Œ ㅤ
Œ ㅤ - avatar
+ 1
Okay !
13th Jan 2022, 5:22 PM
Romaric
+ 1
How can I post some code with pc?
13th Jan 2022, 5:49 PM
Romaric
+ 1
Romaric Simple; make a new code in SoloLearn (copy and paste, if you have already made the code in some place other than SoloLearn) and clikc on the share icon (top right), copy the link and paste it here
13th Jan 2022, 6:11 PM
Œ ㅤ
Œ ㅤ - avatar
+ 1
Okay
13th Jan 2022, 6:33 PM
Romaric
13th Jan 2022, 6:36 PM
Romaric
+ 1
I tried something in function saisie() but it don't work. When i make a function in which the user puts the coefficient and the degree successively, the program work correctly but the tutor tells that the user must enter whole of the polynomial at once
13th Jan 2022, 6:42 PM
Romaric
+ 1
Romaric Hmm, so how about implementing a parser? It takes an input polynomial and separates it into its constituent terms, par example, celui-ci:- "3x+45-2x^2" -> {"3x", "45", "-2x^2"}
13th Jan 2022, 6:54 PM
Œ ㅤ
Œ ㅤ - avatar
+ 1
This will not help me too much. In the example you gave, I still need to recover the coefficients and degrees without the "X"
13th Jan 2022, 8:18 PM
Romaric
+ 1
Romaric Here's what you wanna do: 1. Take the input polynomial 2. Split it into terms (whenever a plus or a minus is encountered) 3. The starting of each term is the coefficient. If the starting is an alphabet instead, then the coefficient is 1. If the 'caret' sign isn't specified in a given term, then the power is 1. Else, read from between the caret and the end, like this: "2x^2" -> {"coeff": 2, "pow": 2, "var_name": "x"} Now, just sort the terms by their power; add the terms with the same power.
14th Jan 2022, 1:53 AM
Œ ㅤ
Œ ㅤ - avatar
+ 1
I see! With which function in C can i split the input?
14th Jan 2022, 10:34 AM
Romaric
+ 1
Romaric You may use the strtok() function from the string.h header file to split a string (Google about it for more info). Here's how you can do it without including the string.h header: https://code.sololearn.com/cTBD1eb6B6q9/?ref=app Just make sure to not give an unsimplified polynomial as the first argument to to_poly()
14th Jan 2022, 6:47 PM
Œ ㅤ
Œ ㅤ - avatar
+ 1
Thanks for your contribution 🙏😊 You help me so much
14th Jan 2022, 11:30 PM
Romaric
+ 1
Your code work well!
14th Jan 2022, 11:30 PM
Romaric
+ 1
Romaric Bien, but make sure to post the completed code here for us to see!
15th Jan 2022, 2:47 AM
Œ ㅤ
Œ ㅤ - avatar
+ 1
Okay
15th Jan 2022, 10:58 PM
Romaric