Notes
Notes - notes.io |
using namespace std;
template <typename t>
class Queue
{
int rear, front;
int size;
t *arr;
public:
Queue(int s)
{
front = rear = -1;
size = s;
arr = new t[s];
}
void createQueue(t value)
{
if ((front == 0 && rear == size - 1) ||
(rear == (front - 1) % (size - 1)))
{
cout << "queue full" << endl;
return;
}
else if (front == -1)
{
front = rear = 0;
arr[rear] = value;
}
else if (rear == size - 1 && front != 0)
{
rear = 0;
arr[rear] = value;
}
else
{
rear++;
arr[rear] = value;
}
}
t deQueue()
{
if (front == -1)
{
cout << "queue empty" << endl;
}
t data = arr[front];
arr[front] = -1;
if (front == rear)
{
front = -1;
rear = -1;
}
else if (front == size - 1)
front = 0;
else
front++;
return data;
}
void displayQueue()
{
if (front == -1)
{
cout << "queue empty" << endl;
return;
}
cout << "Elements in Queue are: " << endl;
if (rear >= front)
{
for (int i = front; i <= rear; i++)
cout<< arr[i]<<endl;
}
else
{
for (int i = front; i < size; i++)
cout << arr[i];
for (int i = 0; i <= rear; i++)
cout << arr[i];
}
}
};
#include "circular"
int main()
{
cout << "circular queue of type int" << endl;
Queue<int> q1(5);
q1.createQueue(14);
q1.createQueue(22);
q1.displayQueue();
cout << "Deleted :" << q1.deQueue() << endl;
q1.displayQueue();
cout << "circular queue of type double" << endl;
Queue<double> q2(4);
q2.createQueue(14.44);
q2.createQueue(22.23);
q2.displayQueue();
cout << "Deleted :" << q2.deQueue() << endl;
q2.displayQueue();
getchar();
return 0;
}
#include<iostream>
using namespace std;
class one
{
int a;
public:
void set(int x)
{
a = x;
}
friend class two;
};
class two
{
int b;
public:
void set_a(one& o, int v)
{
o.a = v;
cout << " value of a ="<<o.a << endl;
}
};
int main()
{
one ob1;
two ob2;
ob2.set_a(ob1, 5);
getchar();
return 0;
}
#include <iostream>
using namespace std;
template <typename T>
class Stack {
int top;
public:
T a[5];
Stack() { top = -1; }
bool push(T x)
{
if (top >= 5) {
cout << "Stack Overflow";
return false;
}
else {
a[++top] = x;
cout << x << " pushed into stackn";
return true;
}
}
T pop()
{
if (top < 0) {
cout << "Stack Underflow";
return 0;
}
else {
T x = a[top--];
return x;
}
}
int peek()
{
if (top < 0) {
cout << "Stack is Empty";
}
else {
int x = a[top];
return T;
}
}
bool isEmpty()
{
return (top < 0);
}
};
#include"stack"
int main()
{
Stack <int>s1;
Stack <double>s2;
Stack <char>s3;
s1.push(10);
s1.push(20);
s1.push(30);
cout << s1.pop() << " Popped from int stackn";
s2.push(10.33);
s2.push(20.24);
s2.push(30.33);
cout << s2.pop() << " Popped from double stackn";
s3.push('h');
s3.push('a');
s3.push('t');
cout << s3.pop() << " Popped from char stackn";
getchar();
return 0;
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team