Suppose G is a directed graph with vetices a, b, c, d, e, f with adjency matrix
ID: 3569521 • Letter: S
Question
Suppose G is a directed graph with vetices a, b, c, d, e, f with adjency matrix (see image below)
Find :
(a) the number of edges in G.
(b) the degree of each vertex.
(c) the number of loops.
(d) the length of the longest simple path in G.
(e) the number of components in G.
(f) the shortest distance between vertex a and vertex c ?
Need to get this done by 12!!
Suppose G is a directed graph with vetices a, b, c, d, e, f with adjency matrix (see image below) Find : (a) the number of edges in G. (b) the degree of each vertex. (c) the number of loops. (d) the length of the longest simple path in G. (e) the number of components in G. (f) the shortest distance between vertex a and vertex c ?Explanation / Answer
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 50
int size;
// Defining the stack structure
struct stack {
int arr[MAX];
int top;
};
// Initializing the stack(i.e., top=-1)
void init_stk(struct stack *st) {
st->top = -1;
}
// Entering the elements into stack
void push(struct stack *st, int num) {
if (st->top == size - 1) {
printf(" Stack overflow(i.e., stack full).");
return;
}
st->top++;
st->arr[st->top] = num;
}
//Deleting an element from the stack.
int pop(struct stack *st) {
int num;
if (st->top == -1) {
printf(" Stack underflow(i.e., stack empty).");
return NULL;
}
num = st->arr[st->top];
st->top--;
return num;
}
void display(struct stack *st) {
int i;
for (i = st->top; i >= 0; i--)
printf(" %d", st->arr[i]);
}
int main() {
int element, opt, val;
struct stack ptr;
init_stk(&ptr);
printf(" Enter Stack Size :");
scanf("%d", &size);
while (1) {
printf(" tSTACK PRIMITIVE OPERATIONS");
printf(" 1.PUSH");
printf(" 2.POP");
printf(" 3.DISPLAY");
printf(" 4.QUIT");
printf(" ");
printf(" Enter your option : ");
scanf("%d", &opt);
switch (opt) {
case 1:
printf(" Enter the element into stack:");
scanf("%d", &val);
push(&ptr, val);
break;
case 2:
element = pop(&ptr);
printf(" The element popped from stack is : %d", element);
break;
case 3:
printf(" The current stack elements are:");
display(&ptr);
break;
case 4:
exit(0);
default:
printf(" Enter correct option!Try again.");
}
}
return (0);
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 50
int size;
// Defining the stack structure
struct stack {
int arr[MAX];
int top;
};
// Initializing the stack(i.e., top=-1)
void init_stk(struct stack *st) {
st->top = -1;
}
// Entering the elements into stack
void push(struct stack *st, int num) {
if (st->top == size - 1) {
printf(" Stack overflow(i.e., stack full).");
return;
}
st->top++;
st->arr[st->top] = num;
}
//Deleting an element from the stack.
int pop(struct stack *st) {
int num;
if (st->top == -1) {
printf(" Stack underflow(i.e., stack empty).");
return NULL;
}
num = st->arr[st->top];
st->top--;
return num;
}
void display(struct stack *st) {
int i;
for (i = st->top; i >= 0; i--)
printf(" %d", st->arr[i]);
}
int main() {
int element, opt, val;
struct stack ptr;
init_stk(&ptr);
printf(" Enter Stack Size :");
scanf("%d", &size);
while (1) {
printf(" tSTACK PRIMITIVE OPERATIONS");
printf(" 1.PUSH");
printf(" 2.POP");
printf(" 3.DISPLAY");
printf(" 4.QUIT");
printf(" ");
printf(" Enter your option : ");
scanf("%d", &opt);
switch (opt) {
case 1:
printf(" Enter the element into stack:");
scanf("%d", &val);
push(&ptr, val);
break;
case 2:
element = pop(&ptr);
printf(" The element popped from stack is : %d", element);
break;
case 3:
printf(" The current stack elements are:");
display(&ptr);
break;
case 4:
exit(0);
default:
printf(" Enter correct option!Try again.");
}
}
return (0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.