Ass 4
Ass 4
Inout list
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int vertex;
struct node *next;
}NODE;
NODE *list[10];
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int vertex;
struct node *next;
}NODE;
NODE *list[10];
int create(int a[10][10],int n){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]=0;
if(i!=j){
printf("\nIs there edge between %d & %d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
}
}
void clist(int a[10][10],int n){
NODE *temp,*newnode;
for(int i=0;i<n;i++){
list[i]=NULL;
for(int j=0;j<n;j++){
if(a[i][j]==1){
newnode=(NODE *)malloc(sizeof(NODE));
newnode->vertex=j+1;
newnode->next=NULL;
if(list[i]==NULL)
list[i]=temp=newnode;
else
temp->next=newnode;
temp=newnode;
}
}
}
}
void recdfs(int a[20][20],int n,int v){
static int visited[20]={0};
visited[v]=1;
printf("v%d\t",v+1);
for(int w=0;w<n;w++){
if((a[v][w]==1)&&(visited[w]==0))
recdfs(a,n,w);
}
}
int main(){
int a[20][20],n;
printf("\nEnter the no. of vertex: ");
scanf("%d",&n);
create(a,n);
clist(a,n);
recdfs(a,n,0);
}
4.listbfs
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 20
typedef struct{
int data[MAXSIZE];
int front, rear;
}QUEUE;