0% found this document useful (0 votes)
8 views5 pages

Seta1 C

The document contains C code to create and display an adjacency list representation of a graph. It takes the number of vertices as input, creates the graph based on edge inputs, and displays the adjacency list of each vertex.

Uploaded by

Black Adam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Seta1 C

The document contains C code to create and display an adjacency list representation of a graph. It takes the number of vertices as input, creates the graph based on edge inputs, and displays the adjacency list of each vertex.

Uploaded by

Black Adam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT 4

SET A(1)

#include<stdio.h>

#include<stdlib.h>

typedef struct node

int vertex;

struct node *next;

}node;
node *v[10];
void create(int m[10][10], int n)

int i,j;

struct node *temp, *newnode;

for(i=0; i<n; i++)

v[i] = NULL;

for (j=0; j<n; j++)

if(m[i][j]==1)

newnode=(struct node *) malloc(sizeof(struct node));

newnode->next = NULL;

newnode-> vertex =j+1;

if(v[i]==NULL)

v[i] = temp = newnode;

}
else

temp -> next = newnode;

temp= newnode;

void display(int n)

struct node *temp;

int i;

for (i=0; i<n; i++)

printf("\nv%d | ",i+1);

temp = v[i];

while (temp)

printf("v%d -> ", temp -> vertex);

temp = temp -> next;

printf("null");

void main()

{
int m[10][10],n,choice;

printf("Enter no. of vertices:");

scanf("%d",&n);

while(1)

printf("1.create\n2.display\n3.exit");

printf("\nEnter ur choice:");

scanf("%d",&choice);

switch(choice)
{

case 1:

create(m,n);

break;

case 2:

display(n);

break;

case 3:

exit(0);

/*Enter no. of vertices:4

1.create

2.display

3.exit

Enter ur choice:1

Is there any edge from 1 to 1:0


Is there any edge from 1 to 2:1

Is there any edge from 1 to 3:1

Is there any edge from 1 to 4:0

Is there any edge from 2 to 1:0

Is there any edge from 2 to 2:0

Is there any edge from 2 to 3:1

Is there any edge from 2 to 4:1

Is there any edge from 3 to 1:0

Is there any edge from 3 to 2:0


Is there any edge from 3 to 3:0

Is there any edge from 3 to 4:1

Is there any edge from 4 to 1:0

Is there any edge from 4 to 2:0

Is there any edge from 4 to 3:0

Is there any edge from 4 to 4:0

1.create

2.display

3.exit

Enter ur choice:2

v1 | v2 -> v3 -> null

v2 | v3 -> v4 -> null

v3 | v4 -> null

v4 | null

1.create

2.display

3.exit
Enter ur choice:3*/

You might also like