Пример #1
0
//-------------------< ONP na drzewo >-------------------
wezel* ONPnadrzewo(const char* onp)
{
	stack stos;
	stack_init(&stos);

	char bufor[12];
	int bufor_idx = 0;
	for (int i = 0; onp[i] != '\0'; i++)
	{
		if (isdigit(onp[i]) || onp[i] == '-' && isdigit(onp[i + 1])) //dodawanie cyfr do bufora
		{
			bufor[bufor_idx] = onp[i];
			bufor_idx++;
			bufor[bufor_idx] = '\0';
		}
		else //dodawanie wêz³a do stosu
		{
			wezel *tmp;
			switch (onp[i])
			{
			case ' ':
				if(bufor_idx)
				{
					stack_push(&stos, wartosc(atoi(bufor)));
					bufor_idx = 0;
				}
				break;
			case '+':
				tmp = stack_pop(&stos);
				stack_push(&stos, op(suma, stack_pop(&stos), tmp));
				break;
			case '-':
				tmp = stack_pop(&stos);
				stack_push(&stos, op(roznica, stack_pop(&stos), tmp));
				break;
			case '*':
				tmp = stack_pop(&stos);
				stack_push(&stos, op(mnozenie, stack_pop(&stos), tmp));
				break;
			case '/':
				tmp = stack_pop(&stos);
				stack_push(&stos, op(dzielenie, stack_pop(&stos), tmp));
				break;
			}
		}
	}
	wezel *tmp = stack_pop(&stos);
	stack_free(&stos);
	return tmp;
}
Пример #2
0
int main()
{
    Lista l = inicjuj();
    dodaj(5.0,&l);
    wypisz_liste(l);
    dodaj(4.0,&l);
    wypisz_liste(l);
    dodaj(3.0,&l);
    wypisz_liste(l);
    dodaj(2.0,&l);
    wypisz_liste(l);
    dodaj_na_koniec(1.0,&l);
    wypisz_liste(l);
    dodaj_na_koniec(7.0,&l);
    wypisz_liste(l);
    usun(l);
    wypisz_liste(l);
    wartosc(l);
    wypisz_liste(l);
    printf("\nDlugosc: %d",dlugosc(l));
    return 0;
}