Cod sursa(job #1226518)

Utilizator vevuiocsaIocsa Valeriu Ionut vevuiocsa Data 5 septembrie 2014 20:45:47
Problema BFS - Parcurgere in latime Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include <iostream>

using namespace std;

struct Node
{
    int v;
    Node *prev;

};
struct Stack
{
    Node *top;

    void Push(int v)
    {
        if(top==NULL)
        {
            top=new Node;
            top->v=v;
            top->prev=NULL;
        }
        else
        {
            Node*aux=new Node;
            aux->v=v;
            aux->prev=top;
            top=aux;
        }
    }
    void Pop()
    {
        if(top!=NULL)
        {
            Node *aux = top->prev;
            delete top;
            top=aux;
        }
    }
    int Top()
    {
        if(top!=NULL)
            return top->v;
        else
            return -1;
    }
};
int main()
{
    Stack s;
    s.top = NULL;
    s.Push(2);
    s.Push(3);
    cout << s.Top() << "\n";
    s.Pop();
    cout << s.Top() << "\n";
    return 0;
}