Add to Favorites    Make Home Page 9416 Online  
 Language Categories  
 Our Services  

Home » C Home » Data Structures Home » stacks using array & linked list

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title stacks using array & linked list
Author Niraj Khatod
Author Email nirajkhatod [at] rediffmail.com
Description operations on stack-push,pop,display implemented using both
array & linked list
Category C » Data Structures
Hits 375488
Code Select and Copy the Code
Code : ******************************************************************* IMPLEMENTATION OF STACKS USING ARRAY & USING LINKED LIST -Niraj khatod ,pune ********************************************************************/ #include<stdio.h> #include<conio.h> #include<malloc.h> #define MAX 10 struct st_a{ int topmost; int stack[MAX] ; }; struct st_a s; struct stl{ int data; struct stl*next ; }*top,*p,*q; void stack_array(); void stack_llist(); void main() { int i,ch,ch1; char c; clrscr(); printf(" PROGRAM TO IMPLEMENT STACKS USING ARRAY & USING LINKED LIST"); do{ printf(" Select method to implement stacks... 1.Array 2.linked list 3.Exit your choice: "); scanf("%d",&ch); switch(ch) { case 1: stack_array(); break; case 2: stack_llist(); break; case 3: exit(); default: printf(" Invalid choice"); break; } printf("Return to main menu?y/n:"); scanf("%s",&c); } while(c=='y'); getch(); } void stack_array() { void push_array(); void pop_array(); void display_array(); int i,ch2 ; char c1; printf(" IMPLEMENTAION OF STACKS USING ARRAY "); do { printf(" *******MENU*******"); printf(" 1.Push 2.Pop 3.Display 4.Exit your choice:"); scanf("%d",&ch2); switch(ch2) { case 1: push_array(); break; case 2: pop_array(); break; case 3: display_array(); break; case 4: exit(); default: printf(" Invalid choice"); break; } printf(" Want to perform another operation?y/n:"); scanf("%s",&c1); } while(c1=='y'); } int full() { if(s.topmost==MAX) return 1; else return 0; } int empty() { if(s.topmost==0) return 1; else return 0; } void push_array() { int full(); char ch3; s.topmost=0; do{ if(full()==1) { printf(" The Stack is full!!"); break; } else { s.topmost++; printf(" Enter the Element to be pushed : "); scanf("%d",&s.stack[s.topmost]); printf(" Push another element?y/n?:"); //flushall(); scanf("%s",&ch3); } } while(ch3=='y' || ch3=='Y'); } void pop_array() { int empty(); char ch; do{ if(empty()==1) { printf(" The Stack is Empty!!"); break; } else { printf("%d has been POPPED!",s.stack[s.topmost]); s.stack[s.topmost--]=0; printf(" Pop other element?y/n:"); //flushall(); scanf("%s",&ch); } } while(ch=='y' || ch=='Y'); } void display_array() { int i; if(empty()==1) printf(" No Records!!!!!!"); else { printf(" The contents of the stack are.... "); for(i=s.topmost ;i>=1; i--) printf(" %d",s.stack[i]); } } /* Implementation of stacks using linked list */ void stack_llist() { int* push_llist(struct stl *,struct stl *); int* pop_llist(struct stl *,struct stl *); void display_llist(struct stl *); int i,ch5 ; char c5; printf(" IMPLEMENTAION OF STACKS USING LINKED LIST "); do { printf(" *****MENU*******"); printf(" 1.Push 2.Pop 3.Display 4.Exit your choice:"); scanf("%d",&ch5); switch(ch5) { case 1: top=push_llist(top,p); break; case 2: top=pop_llist(top,q); break; case 3: display_llist(top); break; case 4: exit(); default: printf(" Invalid choice"); break; } printf(" Want to perform another operation?y/n:"); scanf("%s",&c5); }while(c5=='y'); } int* push_llist(struct stl *top,struct stl *p) { void display_llist(struct stl *); int num; char c7; do{ printf(" Enter the Element to be pushed : "); scanf("%d",&num); p=malloc(sizeof(struct stl)); p->data=num; p->next=NULL; if(top==NULL) top=p; else { p->next=top; top=p; } printf(" Push another element?y/n?:"); scanf("%s",&c7); } while(c7=='y' || c7=='Y'); return(top); } int* pop_llist(struct stl *top,struct stl *q) { void display_llist(struct stl *); char c8; do{ if(top==NULL) { printf(" List is empty!"); break; } else { q=top; top=top->next; q->next=NULL; free(q); } printf(" Pop other element?y/n:"); scanf("%s",&c8); } while(c8=='y' || c8=='Y'); return(top); } void display_llist(struct stl *top) { if(top==NULL) printf("stack is empty!!"); else { q=top; printf ( " contents of stack are: " ) ; while ( q!= NULL ) /* traverse the entire linked list */ { printf ( " %d ", q -> data ) ; q = q -> next ; } } }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi ¦Õ¤ ?¤Ð Ãß??ÝÐÝ
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=906


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review