Witam mam problem z zamiana kodu c na c++ .Bardzo bym prosił o pomoc.
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#define ever ;;
using namespace std;
int top(int *stos)
{
return stos[stos[0]];
}
int pop(int *stos)
{
--stos[0];
stos = realloc(stos, (stos[0]+1)*sizeof(*stos));
return stos[0];
}
void push(int *stos, int element)
{
++stos[0];
stos = realloc(stos, (stos[0]+1)*sizeof(*stos));
stos[stos[0]] = element;
}
int main()
{
int akcja, element;
int *stos = calloc(1, sizeof(*stos));
for(ever)
{
cout<<("\nCo mam zrobic:\n0 - wyjscie\n1 - top\n2 - pop\n3 - push\n");
cin>>akcja;
switch(akcja)
{
case 1:
if(stos[0]>0)
cout<<"Wartosc ze szczytu: .\n", top(stos);
else
cout<<"Stos jest pusty..\n";
break;
case 2:
if(stos[0]<1)
cout<<"Stos jest pusty..\n";
else
cout<<"Usunieto element. ", pop(stos);
break;
case 3:
cout<<"Wartosc do dodania: ";
cin>>element;
push(stos, element);
cout<<"Dodano element.\n";
break;
case 0:
return 0;
default:
cout<<"Blad !\n";
}
}
free(stos);
system("PAUSE");
return 0;