linked list stack
#include <stdio.h>
#include <stdlib.h>
struct Node{
int data;
struct Node *next;
};
void linkedListTraversal(struct Node*ptr){
while(ptr!=NULL){
printf("Element: %d\n", ptr->data);
ptr = ptr->next;
}
}
int isEmpty(struct Node*top ){
if(top==NULL){
return 1;
}
else{
return 0;
}
}
int isFull(struct Node*top ){
struct Node*n=(struct Node*)malloc(sizeof(struct Node));
if(n==NULL){
return 1;
}
else{
return 0;
}
}
struct Node* push(struct Node*top, int x){
if(isFull(top)){
printf("Stack Overflow\n");
}
else{
struct Node*n=(struct Node*)malloc(sizeof(struct Node));
n->data= x;
n->next= top;
top = n;
return top;
}
}
int main()
{
struct Node *top = NULL;
top = push(top, 78);
top = push(top, 79);
top = push(top, 80);
top = push(top, 81);
linkedListTraversal(top);
return 0;
}
Comments
Post a Comment