-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cfe1fa
commit 3f63c10
Showing
17 changed files
with
667 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Oops, something went wrong.