Tower of Hanoi Non-Recursive Using Stack program in C programming YASH PAL, March 5, 2023May 28, 2024 In this post tutorial, we will write a Tower of Hanoi Non-recursive using a stack program in a c programming language with practical program code examples and a complete full explanation with output.[br]#include<stdio.h> #include<conio.h> #define MAXSTK 10 struct item { int n; char beg; char end; char aux; char add; }; struct stack { int top; struct item data[MAXSTK]; }; void push(struct stack *, struct item); struct item pop(struct stack *); void tower(int, char, char, char); void main() { int n; clrscr(); printf("Enter how many rings"); scanf("%d",&n); tower(n,'A','B','C'); getch(); } void push(struct stack *p, struct item it) { if(p->top == MAXSTK-1) { printf("Stack is full"); return; } p->top++; p->data[p->top] = it; } struct item pop(struct stack *p) { struct item it; if(p->top == -1) { printf("Stack is empty"); return it; } it = p->data[p->top]; p->top--; return(it); } void tower(int n, char beg, char aux, char end) { struct stack s1; struct item currentitem; int t; s1.top = -1; step1: if(n==1) { printf("\n Disk No 1 is transferred from %c to %c",beg,end) goto step5; } step2: currentitem.n = n; currentitem.beg = beg; currentitem.end = end; currentitem.aux = aux; currentitem.add = 3; push(&s1,currentitem); n--; t = end; end = aux; aux = t; goto step1; step3: printf("\n Disk no %d is transferred from %c to %c",n,beg,end); step4: currentitem.n = n; currentitem.beg = beg; currentitem.end = end; currentitem.aux = aux; currentitem.add = 5; push(&s1, currentitem); n--; t = aux; aux = beg; beg = t; goto step 1; step5: if(s1.top == -1) return; currentitem = pop(&s1); n = currentitem.n; beg = currentitem.beg; end = currentitem.end; aux = currentitem.aux; switch(currentitem.add) { case 3: goto step3; case 5: goto step5; } } Facebook X.com LinkedIn Instagram Pinterest More Share this content Social Media Facebook X.com Reddit Tumblr Snapchat VKontakte Odnoklassniki Weibo QQ Douban Baidu Digg StumbleUpon Flipboard Mix Professional LinkedIn Slack Zoom XING Behance Dribbble Messaging WhatsApp Telegram Microsoft Teams Messenger Viber Line WeChat SMS Kik Threema Signal Visual Pinterest Instagram Communication Email Bookmarking Pocket Evernote Instapaper Developer GitHub GitLab Stack Overflow Dev.to Hacker News Gaming Discord Twitch Video YouTube TikTok Publishing Medium WordPress Blogger Entertainment Spotify SoundCloud Academic Mendeley ResearchGate Academia Finance Coinbase Shopping Amazon eBay Etsy Lifestyle Foursquare Yelp Utility Copy Link Print QR Code data structures Programs stack DSAprogramsstack