10 Mart 2010 Çarşamba

C++ da Stack Eleman Ekleme Ve Çıkarma

//www.ethemsulan.com
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct cell *stack;
struct cell{
       int element;
       stack next;
       };
void intial(stack *ps){
     *ps=NULL;
     }
bool empty(stack *ps){
     if(*ps==NULL) return true;
     else return false;
     }
bool ful(stack *ps){return false;}
void push(int x,stack *ps){
     stack k;
k=(stack)malloc(sizeof(struct cell));
     k->element=x;
     k->next=*ps;
     *ps=k;
     }
int pop(stack *ps,int *px){
    if(*ps==NULL) return false;
    else{
    *px=(*ps)->element;
    *ps=(*ps)->next;
    return *px;
    }
    }
int main(int argc, char *argv[])
{
    stack ob;
    int next;
    int k;
    intial(&ob);
    push(10,&ob);
    push(20,&ob);
    push(30,&ob);
    next=pop(&ob,&k);
    printf("%d\n",next);
    next=pop(&ob,&k);
    printf("%d\n",next);
    next=pop(&ob,&k);
    printf("%d\n",next);
  system("PAUSE");	
  return 0;
}

Hiç yorum yok:

Yorum Gönder