Új hozzászólás Aktív témák
-
Lacces
őstag
Hogyan kell kivenni a whitespaceket egy Stringből?
Probáltam még a String str = input.Split(' '); -t is használni, de akkor a char x=str[i]; -nél kerültem bajba, a fordító mindig kijelenti, hogy expliciten sem lehet string-et char-á konvertálni.
Trim()-et is bevetettem, de az sem segített rajtamString str = "5 + ( ( 1 + 2 ) * 4 ) −3"; Ennél egy StackEmpty hibát dob ki,
de ha a string-ben nincsenek whitespacek, akkor nem dobja ki a hibátstatic String LengyelFormaKonvertalas(String input)
{
Stack stack = new Stack();
String str = input.Trim();
StringBuilder formula = new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
char x=str[i];
if (x == '(')
stack.Push(x);
else if (IsOperandus(x))
{
formula.Append(x);
}
else if (IsOperator(x))
{
if (stack.Count>0 && (char)stack.Peek()!='(' && Prior(x)<=Prior((char)stack.Peek()) )
{
char y = (char)stack.Pop();
formula.Append(y);
}
if (stack.Count > 0 && (char)stack.Peek() != '(' && Prior(x) < Prior((char)stack.Peek()))
{
char y = (char)stack.Pop();
formula.Append(y);
}
stack.Push(x);
}
else
{
char y=(char)stack.Pop();
if (y!='(')
{
formula.Append(y);
}
}
}
while (stack.Count>0)
{
char c = (char)stack.Pop();
formula.Append(c);
}
return formula.ToString();
}
Új hozzászólás Aktív témák
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- HP 15S FHD LED Matt i5-1135G7 4.2Ghz 16GB RAM 512GB SSD Intel Iris XE Graphics Win11 Garancia
- Targus - USB-C Dual HDMI 4K HUB - 2 x HDMI (120Hz)
- ÚJ Xiaomi Mi Robot Vacuum Mop Essential robotporszívó feltörlő 2db 1999 Ft
- Seagate Exos X18 16TB SAS merevlemez
- ÁRGARANCIA!Épített KomPhone i7 14700KF 32/64GB RAM RX 9070 XT 16GB GAMER PC termékbeszámítással
Állásajánlatok
Cég: FOTC
Város: Budapest