".C" file is available in downloadable format at :
(Open the link and click on the download arrow on the top right to download the file.)
Given Below is the code for implementation of stack using Linked List:
---------------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#define M 5
void readgraph ();
int a[M][M];
void main ()
{
int s,t, choice;
printf("\nHello and Welcome to graphs.\n\n");
printf("\nFirst of all, enter the graph");
readgraph();
while (1)
{
printf("\n\n1.Check connections\n2.Exit\nYour choice : ");
scanf("%d", &choice);
switch (choice)
{
{
case 1:
printf("\nEnter the indices to check whether points A and B are connected or not : ");
printf("\nFirst Index: "); scanf("%d", &s);
printf("\nSecond Index: "); scanf("%d", &t);
if ( a[s][t] == 1 )
printf("\n Yes, they are connected");
else
printf("\n No, they are not connected");
}
case 2 :
exit(0);
default :
printf("\nEnter valid option");
}
}
void readgraph ()
{
int i,j, choice, num;
printf("\nWhat's the number of entries?\nWell, it's : ");
scanf("%d", &num);
printf ("\nKey in 1 for Yes and 0 for No");
for(i=1; i<=num; i++)
{
for (j=1; j<=num; j++)
{
if (i==j)
a[i][j] =0;
else
{
printf("\nIs %d connected to %d : ", i,j);
scanf("%d", &choice);
if (choice==1)
a[i][j] = 1;
else
a[i][j] = 0;
}
}
}
return;
}
Heyoo...I was looking for this thing on the whole fucking internet, and finally landed up here.
ReplyDeleteThanks a lot man, really :)