Assignment - 6: Solution
Assignment - 6: Solution
Assignment - 6: Solution
Question 1.
Solution:
#include <stdio.h>
void main()
int flag,i,count=0;
scanf("%[^\n]%*c", a);
scanf("%[^\n]%*c", b);
if (flag == 1)
for(i=0;a[i]!='\0';i++){
if(a[i]==b[i])
count++;
}
printf("%d",count);
else
printf("-1");
first[a[c]-'a']++;
c++;
c = 0;
{
second[b[c]-'a']++;
c++;
if (first[c] != second[c])
return 0;
return 1;
Question 2:
Solution:
#include <stdio.h>
#include <stdlib.h>
struct node
int vertex;
struct node *next;
};
struct list_entry
};
void init_list_entries()
int i;
list_entries[i].head =
list_entries[i].tail =
NULL;
}
}
return temp;
if(list_entries[b].head == NULL)
list_entries[b].head = node1;
list_entries[b].tail = node1;
else
list_entries[b].tail->next = node1;
list_entries[b].tail = node1;
node2 = make_node(b);
if(list_entries[a].head == NULL)
{
list_entries[a].head = node2;
list_entries[a].tail = node2;
else
list_entries[a].tail->next = node2;
list_entries[a].tail = node2;
return;
void print_adjacent_vertices_of(int n)
printf("%d\n",current->vertex);
current = current->next;
return;
int main()
int num_edges;
int a;
int b;
int n;
int i=0;
scanf("%d", &num_edges);
insert_at_end(a,b);
scanf("%d",&n);
print_adjacent_vertices_of(n);
}
Question 3.
Solution:
#include <stdio.h>
#include<string.h>
void main()
char a[100];
int count=0;
scanf("%[^\n]%*c", a);
count = longestRun(a);
printf("%d",count);
int c = 0,n=1,max_len=1;
for (c ; c < strlen(a); c++)
{ if(a[c]==a[c+1]){
n++;
else{
if(n>max_len)
max_len = n;
n=1;
return max_len;