diff --git a/cicularqueue.cpp b/cicularqueue.cpp new file mode 100644 index 0000000..bbda887 --- /dev/null +++ b/cicularqueue.cpp @@ -0,0 +1,68 @@ +using namespace std; +#include +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"< +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"<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<data; + front=front->next; + + } + cout<data; + { + + } +} diff --git a/circularlinkedqueue.exe b/circularlinkedqueue.exe new file mode 100644 index 0000000..68aa060 Binary files /dev/null and b/circularlinkedqueue.exe differ diff --git a/circularlinkedqueuee.cpp b/circularlinkedqueuee.cpp new file mode 100644 index 0000000..77217fb --- /dev/null +++ b/circularlinkedqueuee.cpp @@ -0,0 +1,84 @@ +using namespace std; +#include +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"<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<data; + front=front->next; + + } + { + + } +} diff --git a/circularqueue.cpp b/circularqueue.cpp new file mode 100644 index 0000000..118947c --- /dev/null +++ b/circularqueue.cpp @@ -0,0 +1,83 @@ +using namespace std; +#include +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"<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<data; + front=front->next; + + } + cout<data; + { + + } +} diff --git a/circularqueue.exe b/circularqueue.exe new file mode 100644 index 0000000..4050682 Binary files /dev/null and b/circularqueue.exe differ diff --git a/deque.cpp b/deque.cpp new file mode 100644 index 0000000..4d156d5 --- /dev/null +++ b/deque.cpp @@ -0,0 +1,93 @@ +using namespace std; +#include +int left1=-1; +int right1=-1; +int arr[90]={0}; +int size=7; +void right_insertion(int p) +{ + if((left1==-1 )&&(right1==-1)) + { + left1=left1+1; + right1=right1+1; + arr[right1]=p; + } + else if((right1==size-1)&&left1==0) + { + cout<<"overflow"< +int lft=-1; +int rght = -1; +int arr[34]={0}; +int mx=5; +insertion_left1(int p) +{ + if(rght==mx-1&&lft==0) + { + cout<<"overflow"< +struct node +{ + int data; + int pri; + struct node *next=NULL; +}; +struct node* start=NULL; +struct node* createnode() +{ + struct node *temp; + temp = new(struct node); + cin>>temp->data; + cin>>temp->pri; + temp->next=NULL; +} +struct node *insertnode() +{ + struct node *t; + t = createnode(); + struct node *t1; + struct node *k; + + if(start==NULL||t->pripri) + { + t->next=start; + start=t; + } + else + { + t1=start; + while(t1->next!=NULL&&t1->pripri) + { + k=t1; + t1=t1->next; + } + if(t1->pri>t->pri) + { + k->next=t; + t->next=t1; + } + else + {42 + + t1->next=t; + t->next=NULL; + + + } + + } +} +void traverse() +{ + struct node *t; + t=start; + while(t!=NULL) + { + cout<data<<"--> "<pri<next; + } +} +int main() +{ + for(int i=0;i<5;i++) + { + insertnode(); + } + traverse(); +} diff --git a/priorityqueue.exe b/priorityqueue.exe new file mode 100644 index 0000000..3605e45 Binary files /dev/null and b/priorityqueue.exe differ diff --git a/queue.cpp b/queue.cpp new file mode 100644 index 0000000..a8de25e --- /dev/null +++ b/queue.cpp @@ -0,0 +1,59 @@ +using namespace std; +#include +#include +int rear=-1; +int front=-1; +int size=5; +int q[5]; +void insertion(int c) +{ + + if(rear==-1 && front==-1) + { + front+=1; + rear+=1; + q[rear]=c; + } + else if(rear==size-1) + { + cout<<"overflow"<rear) + { + cout<<"underflow"< +#include + stacks; + stacks2; + +void deletion() + { + int p=0; + if((!s.empty())||s2.empty()) + { + while(!s.empty()) + { + p=s.top(); + s.pop(); + s2.push(p); + + } + s2.pop(); + return s2; + } + else + { + /*while(!s2.empty()) + { + p=s2.top(); + s2.pop(); + s.push(p); + }*/ + s2.pop(); + return s2; + } + } +int main() +{ +//stackk; +s.push(3); +s.push(31); +s.push(23); +s.push(45); +s.push(37); +deletion(); +/*k=deletion(); +k=deletion(); +k=deletion();*/ +if(s.empty()) +{ + + k.push(100); + + } +else +{ + s2.push(100); +} +while(!k.empty()) +{ + cout<