#include<iostream>
#include<cstdlib>
using namespace std;/*white-2
grey-1
black-0*/
int main()
{
struct s1
{
int sm;
int dis;
int key;
int color;
struct s1 *next;
int adj[100];
int count;
};
int tim;
typedef struct s1 node;
node *pointer(int ele);
node *head=(node *)malloc(sizeof(node));
void insertion(int A,int in)
tim=0;
node *p;
p=head;
cout<<"enter the vertices in order"<<"enter -1 at end";
int in;
cin>>in;
head->color=2;
while(in!=-9)
{
node *p1=(node *)malloc(sizeof(node));
p->next=p1;
p->key=in;
p->color=2;
p->sm=100;
p=p->next;
cin>>in;
}
p->next=NULL;
cout<<"enter the edges in order"<<"enter 0 0 at end";
int a[100],b[100];
int i=-1,k=0;
a[i]=-5;
b[i]=-5;
while(a[i]!=-9)
{
i++;
k++;
cin>>a[i]>>b[i];
}
node *p2;
int l;
int h=0;
for(p2=head;p2->next!=NULL;p2=p2->next)
{
p2->count=0;
h=0;
for(l=0;l<k;l++)
{
if(p2->key==a[l])
{
(p2->count)++;
(p2->adj[h])=b[l];
h++;
}
}
}
cout<<"enter the no. of edges";
int in;
cin>>in;
cout<<"enter the weights";
int we[in];
int i=0;
for(;i<in;i++)
{
cin>>we[i];
}
insertion(we,in)
return 0;
}
insertion(int A,int in)
{
for(int j=0;j<in;j++)
{
int key=A[j];
int i=j-1;
while((i>=0)&&(A[i]>key)
{
A[i+1]=A[i];
i=i-1;
}
A[i]=key;
}
#include<cstdlib>
using namespace std;/*white-2
grey-1
black-0*/
int main()
{
struct s1
{
int sm;
int dis;
int key;
int color;
struct s1 *next;
int adj[100];
int count;
};
int tim;
typedef struct s1 node;
node *pointer(int ele);
node *head=(node *)malloc(sizeof(node));
void insertion(int A,int in)
tim=0;
node *p;
p=head;
cout<<"enter the vertices in order"<<"enter -1 at end";
int in;
cin>>in;
head->color=2;
while(in!=-9)
{
node *p1=(node *)malloc(sizeof(node));
p->next=p1;
p->key=in;
p->color=2;
p->sm=100;
p=p->next;
cin>>in;
}
p->next=NULL;
cout<<"enter the edges in order"<<"enter 0 0 at end";
int a[100],b[100];
int i=-1,k=0;
a[i]=-5;
b[i]=-5;
while(a[i]!=-9)
{
i++;
k++;
cin>>a[i]>>b[i];
}
node *p2;
int l;
int h=0;
for(p2=head;p2->next!=NULL;p2=p2->next)
{
p2->count=0;
h=0;
for(l=0;l<k;l++)
{
if(p2->key==a[l])
{
(p2->count)++;
(p2->adj[h])=b[l];
h++;
}
}
}
cout<<"enter the no. of edges";
int in;
cin>>in;
cout<<"enter the weights";
int we[in];
int i=0;
for(;i<in;i++)
{
cin>>we[i];
}
insertion(we,in)
return 0;
}
insertion(int A,int in)
{
for(int j=0;j<in;j++)
{
int key=A[j];
int i=j-1;
while((i>=0)&&(A[i]>key)
{
A[i+1]=A[i];
i=i-1;
}
A[i]=key;
}