From 3b3d91bf9a8eb5cbb29eec36f06dd53fcaeb3a58 Mon Sep 17 00:00:00 2001 From: Kiran Yadav Date: Sat, 23 Oct 2021 16:58:10 +0530 Subject: [PATCH 1/2] Added program of Linked implementation of a Queue --- Linked_Queue.cpp | 155 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 Linked_Queue.cpp diff --git a/Linked_Queue.cpp b/Linked_Queue.cpp new file mode 100644 index 0000000..268dae3 --- /dev/null +++ b/Linked_Queue.cpp @@ -0,0 +1,155 @@ +# include +using namespace std; +template +class node +{ public: + T info; + node* next; + node(T x, node* n=NULL) + { + info=x; + next=n; + } + +}; +template +class queuetype +{ + node* f,*r; + public : + queuetype() + { + f=r=NULL; + } + int isempty(); + void enqueue(T x); + T dequeue(); + int count(); + void display(); + + +}; +template +int queuetype ::isempty() +{ + if(f==NULL) + { + return 1; + } + else + return -1; +} +template +void queuetype :: enqueue(T x) +{ + node* temp; + temp=new node(x); + if(f==NULL) + f=r=temp; + else + { + r->next=temp; + r=temp; + } +} +template +T queuetype :: dequeue() +{ + int x; + x=f->info; + if(f==r) + { + delete f; + f=r=NULL; + } + else + { + node* temp; + temp=f; + f=f->next; + delete(temp); + } + return x; +} +template +int queuetype :: count() +{ + int ct=0; + node* temp; + for(temp=f; temp!=NULL; temp=temp->next) + { + ct++; + } + return ct; +} +template +void queuetype :: display() +{ + if(f==NULL) + cout<<"Queue is Empty! Nothing to display"<* temp; + cout<<"Elements of Queue from front end to rare end are : "<next) + { + cout<info<<" "; + } + cout< q; + while(c=='y' || c=='Y') + { + cout<<"Main menu :- "<>choice; + switch(choice) + { + case 1 : cout<<"Enter the element you want to add "; + cin>>in; + q.enqueue(in); + q.display(); + break; + case 2 : i=q.isempty(); + if(i==1){ + cout<<"Queue is empty! Nothing to display."<>c; + + } + +} From f9482c0da7ea15afbdd7cf282a08273f286ee2cd Mon Sep 17 00:00:00 2001 From: Kiran Yadav Date: Sat, 23 Oct 2021 17:47:09 +0530 Subject: [PATCH 2/2] Program to find indegree and outdegree of vertices of graph --- IndegreeAndOutdegree.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 IndegreeAndOutdegree.cpp diff --git a/IndegreeAndOutdegree.cpp b/IndegreeAndOutdegree.cpp new file mode 100644 index 0000000..dc15fa1 --- /dev/null +++ b/IndegreeAndOutdegree.cpp @@ -0,0 +1,37 @@ +# include +using namespace std; +int main() +{ int n; +int a[10][10]; + cout<<"Enter the order of the Adjancy matrix of graph"; + cin>>n; + cout<<"Enter the Adjancy Matrix"<>a[i][j]; + } + } + int ch='a'; + int indegree[n]={0}; + int outdegree[n]={0}; + for(int i=0; i