Skip to content

Commit

Permalink
practical file
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyajainn committed Oct 11, 2018
1 parent 1cfe1fa commit 3f63c10
Show file tree
Hide file tree
Showing 17 changed files with 667 additions and 0 deletions.
68 changes: 68 additions & 0 deletions cicularqueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using namespace std;
#include<iostream>
int arr[20];
int front =-1;
int rear=-1;
int size =5;
void insertion(int s)
{
if(rear==-1&&front==-1)
{
rear=rear+1;
front = front+1;
arr[rear]=s;
}
else if(front==0&&rear==size-1)
{
cout<<"overflow"<<endl;
}
else if(front==rear+1)
{
cout<<"overflow"<<endl;
}
else if(front!=0&&rear==size-1)
{
rear=0;
arr[rear]=s;
}
else
{
rear=rear+1;
arr[rear]=s;
}
}
void deletion()
{
if(rear==-1&&front==-1)
{
cout<<"underflow"<<endl;
}
else if(front==rear)
{
front=rear=-1;
}
else if(front==size-1&&front!=rear)
{
front=0;
}
else
{
front=front+1;
}
}
int main()
{
insertion(5);
insertion(10);
insertion(15);
insertion(20);
insertion(25);
deletion();
while(front!=rear)
{
cout<<arr[front]<<endl;
front=front+1;
}
cout<<arr[front]<<endl;

}
Binary file added cicularqueue.exe
Binary file not shown.
84 changes: 84 additions & 0 deletions circularlinkedqueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using namespace std;
#include<iostream>
struct node
{
int data;
struct node* next=NULL;
};
struct node *front=NULL;
struct node *rear=NULL;
struct node *createnode()
{
struct node *p;
p=new(struct node);
cin>>p->data;
p->next=NULL;
}
struct node *insertnode()
{

struct node *p;
p=createnode();
if(front==NULL&&rear==NULL)
{
front=p;
rear=p;
p->next=NULL;
}
else
{
struct node *t;
t=front;
while(t->next!=NULL)
{
t=t->next;
}
t->next=p;
p->next=NULL;
rear=p;
}
}
struct node *deletion()
{
if(rear->next==NULL&&front->next==NULL)
{
front=NULL;
cout<<"nothing to be deleted"<<endl;
}
else if(rear->next==front->next)
{
rear=NULL;
front=NULL;
}
else if(front->next==NULL&&front!=rear)
{
front=NULL;
}
else
{
front = front->next;
}
return front;
}
int main()
{
insertnode();
insertnode();
insertnode();
insertnode();
deletion();
deletion();
deletion();
deletion();
// deletion();
while(front->next!=NULL)
{
cout<<front->data;
front=front->next;

}
cout<<front->data;
{

}
}
Binary file added circularlinkedqueue.exe
Binary file not shown.
84 changes: 84 additions & 0 deletions circularlinkedqueuee.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using namespace std;
#include<iostream>
struct node
{
int data;
struct node* next=NULL;
};
struct node *front=NULL;
struct node *rear=NULL;
struct node *createnode()
{
struct node *p;
p=new(struct node);
cin>>p->data;
p->next=NULL;
}
struct node *insertnode()
{

struct node *p;
p=createnode();
if(front==NULL&&rear==NULL)
{
front=p;
rear=p;
p->next=NULL;
}
else
{
struct node *t;
t=front;
while(t->next!=NULL)
{
t=t->next;
}
t->next=p;
p->next=NULL;
rear=p;
}
}
struct node *deletion()
{
if(rear->next==NULL&&front->next==NULL)
{
front=NULL;
rear=NULL;
cout<<"nothing to be deleted"<<endl;
}
else if(rear->next==front->next)
{
rear=NULL;
front=NULL;
}
else if(front->next==NULL&&front!=rear)
{
front=NULL;
}
else
{
front = front->next;
}
return front;
}
int main()
{
insertnode();
insertnode();
insertnode();
insertnode();
deletion();
deletion();
deletion();
deletion();
deletion();
while(front!=NULL)
{
cout<<front->data;
front=front->next;

}
{

}
}
83 changes: 83 additions & 0 deletions circularqueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using namespace std;
#include<iostream>
struct node
{
int data;
struct node* next=NULL;
};
struct node *front=NULL;
struct node *rear=NULL;
struct node *createnode()
{
struct node *p;
p=new(struct node);
cin>>p->data;
p->next=NULL;
}
struct node *insertnode()
{

struct node *p;
p=createnode();
if(front==NULL&&rear==NULL)
{
front=p;
rear=p;
p->next=NULL;
}
else
{
struct node *t;
t=front;
while(t->next!=NULL)
{
t=t->next;
}
t->next=p;
p->next=NULL;
rear=p;
}
}
/*struct node *deletion()
{
if(rear->next==NULL&&front->next==NULL)
{
cout<<"nothing to be deleted"<<endl;
}
else if(rear->next==front->next)
{
rear=NULL;
front=NULL;
}
else if(front->next==NULL&&front!=rear)
{
front=NULL;
}
else
{
front = front->next;
}
return front;
}*/
int main()
{
insertnode();
insertnode();
insertnode();
insertnode();
//deletion();
//deletion();
//deletion();
// deletion();
// deletion();
while(front->next!=NULL)
{
cout<<front->data;
front=front->next;

}
cout<<front->data;
{

}
}
Binary file added circularqueue.exe
Binary file not shown.
Loading

0 comments on commit 3f63c10

Please sign in to comment.