#include <stdio.h>
#include <stdlib.h>
#define MAX 300000
typedef struct{
int data;
struct node * link;
}node;
node* push(int d,node * top){
static int count =0;
node *tmp;
count++;
if(count > MAX){
printf("over Flow Error...!!n");
return top;
}
tmp =(node *)malloc(sizeof(node));
tmp->link = top;
tmp->data = d;
return tmp;
}
void pl(node *start){
node *tmp;
printf("%d n",start->data);
if(start->link==NULL)return ;
tmp = start->link;
while(1){
printf("%d n",tmp->data);
if(tmp->link == NULL)break;
tmp = tmp->link;
}
}
int pop(node **top){
node *tmp = *top;
if(*top==NULL){
printf("Under Flow Errorn");
return -1;
}
*top = tmp->link;
return tmp->data;
}
main(){
node *top=NULL;
top = push(323,top);
top = push(3,top);
top = push(4,top);
top = push(23,top);
printf("%d <---popped n",pop(&top));
printf("%d <---popped n",pop(&top));
printf("%d <---popped n",pop(&top));
printf("%d <---popped n",pop(&top));
printf("%d <---popped n",pop(&top));
printf("%d <---popped n",pop(&top));
//pl(top);
}
//linkedListStack.h
#define MAX 300000
typedef struct{
int data;
struct node * link;
}node;
node * get_node(){
node *tmp =(node *)malloc(sizeof(node));
tmp->data = 0;
tmp->link = NULL;
}
node* push(int d,node ** top){
static int count =0;
node *tmp;
count++;
if(count > MAX){
printf("over Flow Error...!!n");
return *top;
}
tmp =get_node();
tmp->link = *top;
tmp->data = d;
*top = tmp;
}
void pl(node *start){
node *tmp;
printf("%d n",start->data);
if(start->link==NULL)return ;
tmp = start->link;
while(1){
printf("%d n",tmp->data);
if(tmp->link == NULL)break;
tmp = tmp->link;
}
}
int pop(node **top){
node *tmp = *top;
if(*top==NULL){
printf("Under Flow Errorn");
return 1<<31;
}
*top = tmp->link;
return tmp->data;
}
//linkedlistStacktest.c
#include <stdio.h>
#include <stdlib.h>
#include "linkedListStack.h"
main(){
node *top=NULL;
int tmp;
push(323,&top);
push(3,&top);
push(4,&top);
push(23,&top);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
//pl(top);
}



#include <stdio.h>
#include <stdlib.h>
#define MAX 300000
typedef struct{
int data;
struct node * link;
}node;
node* push(int d,node ** top){
static int count =0;
node *tmp;
count++;
if(count > MAX){
printf("over Flow Error...!!n");
return *top;
}
tmp =(node *)malloc(sizeof(node));
tmp->link = *top;
tmp->data = d;
*top = tmp;
}
void pl(node *start){
node *tmp;
printf("%d n",start->data);
if(start->link==NULL)return ;
tmp = start->link;
while(1){
printf("%d n",tmp->data);
if(tmp->link == NULL)break;
tmp = tmp->link;
}
}
int pop(node **top){
node *tmp = *top;
if(*top==NULL){
printf("Under Flow Errorn");
return 1<<31;
}
*top = tmp->link;
return tmp->data;
}
main(){
node *top=NULL;
int tmp;
push(323,&top);
push(3,&top);
push(4,&top);
push(23,&top);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
tmp =pop(&top);
if(tmp!= 1<<31)
printf("%d <---popped n",tmp);
//pl(top);
}