SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
/*
Linked List Implementation of the Stack in C
Author: Kasun Ranga Wijeweera
Email: krw19870829@gmail.com
Date: 20130501
*/
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
typedef struct stackNode *link;
struct stackNode
{
int data;
link next;
};
typedef struct
{
link top;
}stack;
void initStack(stack *s)
{
s->top=NULL;
}
int isEmpty(stack *s)
{
if((s->top)==NULL)
{
return 0;
}
else
{
return 1;
}
}
void pushStack(stack *s,int x)
{
link t=(link)malloc(sizeof(struct stackNode));
t->data=x;
t->next=s->top;
s->top=t;
}
int popStack(stack *s)
{
link t;
int x;
t=s->top;
x=t->data;
s->top=t->next;
free(t);
return x;
}
void printStack(stack *s)
{
link t=s->top;
while(t!=NULL)
{
printf("%d ",t->data);
t=t->next;
}
}
void main()
{
int x;
stack *s;
clrscr();
s=(stack*)malloc(sizeof(stack));
initStack(s);
pushStack(s,10);
pushStack(s,20);
if(isEmpty(s))
x=popStack(s);
pushStack(s,30);
pushStack(s,40);
pushStack(s,50);
if(isEmpty(s))
x=popStack(s);
printStack(s);
free(s);
getch();
}

Más contenido relacionado

La actualidad más candente (7)

Operasi Matriks dengan Borland C++
Operasi Matriks dengan Borland C++Operasi Matriks dengan Borland C++
Operasi Matriks dengan Borland C++
 
Linklist through struct
Linklist through structLinklist through struct
Linklist through struct
 
Nova microsoft word document
Nova microsoft word documentNova microsoft word document
Nova microsoft word document
 
6.1 Шаблоны классов
6.1 Шаблоны классов6.1 Шаблоны классов
6.1 Шаблоны классов
 
vecotores programacion
vecotores programacionvecotores programacion
vecotores programacion
 
Numeros primos
Numeros primosNumeros primos
Numeros primos
 
ikp213-06-template-c++
ikp213-06-template-c++ikp213-06-template-c++
ikp213-06-template-c++
 

Destacado

Improving the accuracy of k-means algorithm using genetic algorithm
Improving the accuracy of k-means algorithm using genetic algorithmImproving the accuracy of k-means algorithm using genetic algorithm
Improving the accuracy of k-means algorithm using genetic algorithm
Kasun Ranga Wijeweera
 
Digital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in CDigital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in C
Kasun Ranga Wijeweera
 
Implementation of k-means clustering algorithm in C
Implementation of k-means clustering algorithm in CImplementation of k-means clustering algorithm in C
Implementation of k-means clustering algorithm in C
Kasun Ranga Wijeweera
 
Linked List Implementation of Deque in C
Linked List Implementation of Deque in CLinked List Implementation of Deque in C
Linked List Implementation of Deque in C
Kasun Ranga Wijeweera
 
Linked List Implementation of Queue in C
Linked List Implementation of Queue in CLinked List Implementation of Queue in C
Linked List Implementation of Queue in C
Kasun Ranga Wijeweera
 

Destacado (16)

Improving the accuracy of k-means algorithm using genetic algorithm
Improving the accuracy of k-means algorithm using genetic algorithmImproving the accuracy of k-means algorithm using genetic algorithm
Improving the accuracy of k-means algorithm using genetic algorithm
 
Wave ECG
Wave ECGWave ECG
Wave ECG
 
Exercises for Two Dimensional Geometric Transformations
Exercises for Two Dimensional Geometric TransformationsExercises for Two Dimensional Geometric Transformations
Exercises for Two Dimensional Geometric Transformations
 
Flood Filling Algorithm in C
Flood Filling Algorithm in CFlood Filling Algorithm in C
Flood Filling Algorithm in C
 
Computing the Area of a Polygon
Computing the Area of a PolygonComputing the Area of a Polygon
Computing the Area of a Polygon
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Digital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in CDigital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in C
 
Exercises for Convexity of Polygons
Exercises for Convexity of PolygonsExercises for Convexity of Polygons
Exercises for Convexity of Polygons
 
Implementation of k-means clustering algorithm in C
Implementation of k-means clustering algorithm in CImplementation of k-means clustering algorithm in C
Implementation of k-means clustering algorithm in C
 
Access modifiers
Access modifiersAccess modifiers
Access modifiers
 
Principles of Object Oriented Programming
Principles of Object Oriented ProgrammingPrinciples of Object Oriented Programming
Principles of Object Oriented Programming
 
Linked List Implementation of Deque in C
Linked List Implementation of Deque in CLinked List Implementation of Deque in C
Linked List Implementation of Deque in C
 
Boundary Fill Algorithm in C
Boundary Fill Algorithm in CBoundary Fill Algorithm in C
Boundary Fill Algorithm in C
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Linked List Implementation of Queue in C
Linked List Implementation of Queue in CLinked List Implementation of Queue in C
Linked List Implementation of Queue in C
 

Más de Kasun Ranga Wijeweera

Más de Kasun Ranga Wijeweera (20)

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
 

Linked List Implementation of Stack in C