DSF Assignment 4
DSF Assignment 4
DSF Assignment 4
#include<string.h>
Class node
Char ID[10];
Char PIN[10];
Public:
Int age;
String name;
String DOB;
Int comments,like;
Bool vi;
Int in;
Void set_ID()
Cout<<”\n\t ENTER ID : “;
Cin>>ID;
Void set_PIN()
Cin>>PIN;
Char* get_ID()
{
Return ID;
Char* get_PIN()
Return PIN;
};
Class friendlist
Public:
Node *frind;
Friendlist *next;
Int dis;
};
Class user_list
Public:
Node *user;
User_list *next;
Friendlist *frind_list;
};
Class queue
Int rare,front;
Node *Q[50];
Public:
Queue(){rare=front=-1; }
Node* deque();
Int empty();
};
If(front==-1&&rare==-1)
Rare=0;
Front=0;
Else if(((rare+1)%50)==front)
Cout<<”\n\t\tQUEUE IS FULL “;
Return ;
}
Q[rare]=newnode;
Rare=(rare+1)%50;
Node* queue::deque()
Node *temp=NULL;
If(rare==front)
Rare=front=-1;
Else
Temp=Q[front];
Front=(front+1)%50;
Return temp;
Int queue::empty()
If(rare==front)
{
Rare=front=-1;
Return 1;
Else
Return 0;
Class graph
User_list *data;
Public:
Void create();
Void display();
Void make_friend();
Void display_friend();
Void login();
Void BFS();
Void PRIMS();
};
Void graph::PRIMS()
Int visit[20],sourse[20],dist[20];
Void graph::BFS()
Queue Q,q;
Int a[100],ab,max=0;
String max_l;
User_list *temp=data;
Node *element,*temp1,VI;
Friendlist *temp3;
Element=temp->user;
Q.enque(element);
q.enque((node*)100);
for(int i=0;i<100;i++)
a[i]=0;
a[element->in]=1;
//cout<<”\n\telement =>”<<element->name;
While(Q.empty()!=1)
Temp1=Q.deque();
//VI=q.deque();
Ab=temp1->comments;
Temp=data;
If(ab>=max)
Max=ab;
Max_l=temp1->name;
While(temp!=NULL)
If(temp->user->name==temp1->name)
//cout<<”\n\t “<<temp->user->name;
Temp3=temp->frind_list;
While(temp3!=NULL)
//cout<<”\n\t 1)”<<temp3->frind->name;
If(a[temp3->frind->in]==0)
A[temp3->frind->in]=1;
//cout<<”\t ans=>”<<temp1->name;
Q.enque(temp3->frind);
q.enque((node*)1);
Temp3=temp3->next;
//cout<<”\n\t “<<temp->user->name;
Temp=temp->next;
Void graph::login()
Int ch=1;
Char ID[20];
Char PIN[10];
User_list *temp=data;
Cin>>ID;
Cin>>PIN;
While(temp!=NULL)
If((strcmp(temp->user->get_ID(),ID)==0)&&(strcmp(temp->user-
>get_PIN(),PIN)==0))
Int ch=1;
While(ch)
Cin>>ch;
Cout<<”\n\t********************”;
Switch(ch)
Case 1:display_friend_list(temp);
Break;
Case 2:add_friend(temp);
Break;
Case 3:display_details(temp);
Break;
Case 4:display_friend();
Break;
Case 5:ch=0;
Break;
Break;
Temp=temp->next;
Node *temp_node;
Temp_node=temp->user;
Cout<<”\n\tNAME = “<<temp_node->name;
Cout<<”\n\tAGE =”<<temp_node->age;
Int ch=1,flag=0,nots=0,dis;
User_list *temp2=NULL;
String friend_name;
Friendlist *friend1;
Friendlist *temp_friendlist;
Cout<<temp1->user->name;
Ch=1;
While(ch)
Cin>>friend_name;
Cout<<”\n\tENTER DISTANCE “;
Cin>>dis;
Temp2=data;
While(temp2!=NULL)
If(temp2->user->name==friend_name&&temp2->user->name!=temp1->user-
>name)
Flag=1;
Make_friend3(temp2->user->name,temp1->user->name);
Break;
Else
Temp2=temp2->next;
If(flag==1)
Cout<<”\n\tUSER FOUND “;
Friend1=new friendlist();
Friend1->frind=temp2->user;
Friend1->next=NULL;
If(temp1->frind_list==NULL)
Temp1->frind_list=friend1;
Else
Temp_friendlist=temp1->frind_list;
While(temp_friendlist->next!=NULL)
If(temp_friendlist->frind->name==friend_name)
Nots=100;
Temp_friendlist=temp_friendlist->next;
If(nots!=100)
If(temp_friendlist==NULL)
Temp_friendlist=friend1;
Else
Temp_friendlist->next=friend1;
//cout<<”\n\t”<<temp_friendlist->frind->name;
Else
Flag=0;
Cin>>ch;
Int count=0;
Friendlist *temp_friendlist;
Temp_friendlist=temp->frind_list;
While(temp_friendlist!=NULL)
Cout<<++count<<”)>\t”<<temp_friendlist->frind->name;
Temp_friendlist=temp_friendlist->next;
}
}
Void graph::display_friend()
Int a=0,max=0,count=0,top=0;
User_list *temp;
String name;
Friendlist *temp_friendlist;
Temp=data;
While(temp!=NULL)
Temp_friendlist=temp->frind_list;
//cout<<”\n\tENTRY”;
A=0;
While(temp_friendlist!=NULL)
//cout<<”\n\t”<<temp_friendlist->frind->name;
Temp_friendlist=temp_friendlist->next;
A=a+1;
//cout<<”\n\t”<<count<<”]”<<a<<”\n”;
If(a>max)
Max=a;
Top=count;
Name=temp->user->name;
Else
A=0;
Temp=temp->next;
Void graph::make_friend()
Int ch=1,flag=0;
String name;
User_list *temp1=NULL,*temp2=NULL;
String friend_name;
Friendlist *friend1;
Friendlist *temp_friendlist;
Temp1=data;
While(temp1!=NULL)
Cout<<”\n\tENTER friends of “;
Cout<<temp1->user->name;
Ch=1;
While(ch)
Cin>>friend_name;
Temp2=data;
While(temp2!=NULL)
{
If(temp2->user->name==friend_name&&temp1->user->name!=temp2->user-
>name)
Flag=1;
Make_friend3(temp2->user->name,temp1->user->name);
Break;
Else
Temp2=temp2->next;
If(flag==1)
Cout<<”\n\tUSER FOUND “;
Friend1=new friendlist();
Friend1->frind=temp2->user;
Friend1->next=NULL;
If(temp1->frind_list==NULL)
Temp1->frind_list=friend1;
Else
Temp_friendlist=temp1->frind_list;
While(temp_friendlist->next!=NULL)
Temp_friendlist=temp_friendlist->next;
If(temp_friendlist==NULL)
Temp_friendlist=friend1;
Else
Temp_friendlist->next=friend1;
Cout<<”\n\t”<<temp_friendlist->frind->name;
Else
Flag=0;
Cin>>ch;
Temp1=temp1->next;
Int ch=1,flag=0,nots=0;
String name;
User_list *temp1=NULL,*temp2=NULL;
String friend_name;
Friendlist *friend1;
Friendlist *temp_friendlist;
Temp1=data;
While(temp1!=NULL)
If(temp1->user->name==a)
{
Ch=1;
While(ch)
Friend_name=b;
Temp2=data;
While(temp2!=NULL)
If(temp2->user->name==friend_name&&temp1->user->name!=temp2->user-
>name)
Flag=1;
//make_friend2(temp2->user->name,temp1->user->name);
Break;
Else
Temp2=temp2->next;
If(flag==1)
Cout<<”\n\tUSER FOUND “;
Friend1=new friendlist();
Friend1->frind=temp2->user;
Friend1->next=NULL;
If(temp1->frind_list==NULL)
Temp1->frind_list=friend1;
Else
{
Temp_friendlist=temp1->frind_list;
While(temp_friendlist->next!=NULL)
If(temp_friendlist->frind->name==friend_name)
Nots=100;
Temp_friendlist=temp_friendlist->next;
If(nots!=100)
If(temp_friendlist==NULL)
Temp_friendlist=friend1;
Else
Temp_friendlist->next=friend1;
Cout<<”\n\t”<<temp_friendlist->frind->name;
Else
Flag=0;
Ch=0;
Temp1=temp1->next;
Void graph::create()
Int no_user,count=1;
User_list *head=NULL,*pre=NULL;
Node *temp=NULL;
Cin>>no_user;
While(no_user--)
Head=new user_list();
Head->frind_list=NULL;
Head->next=NULL;
Head->user=NULL;
Temp=new node();
Temp->set_ID();
Temp->set_PIN();
Temp->in=count++;
Cout<<”\n\tENTER NAME = “;
Cin>>temp->name;
Cin>>temp->DOB;
Cout<<”\n\tENTER AGE = “;
Cin>>temp->age;
Cin>>temp->like;
Cin>>temp->comments;
Head->user=temp;
If(pre==NULL)
Data=head;
Else
Pre->next=head;
Pre=head;
Void graph::display()
User_list *temp;
Node *temp_node;
Temp=data;
While(temp!=NULL)
{
Temp_node=temp->user;
Cout<<”\n\tNAME = “<<temp_node->name;
Cout<<”\n\tAGE =”<<temp_node->age;
Temp=temp->next;
Int main()
Int ch;
Graph G;
Cout<<”\n\t END “;
G.create();
G.make_friend();
G.BFS();
Do
Cout<<”\n\t5.QUIT\n\t\tENTER CHOICE==”;
Cin>>ch;
Cout<<”\n\t********************”;
Switch(ch)
Case 1:G.login();
Break;
Case 2:G.make_friend();
Break;
Case 3:G.display_friend();
Break;
Case 4:G.display();
Break;
Case 5:ch=0;
Break;
}while(ch);
Return 0;