FDS Codes
FDS Codes
:COSB60
Assignment No. 10
INPUT:
#include <iostream>
#include <cstring>
#include <stack> using
namespace std; int
getWeight(char ch)
{
switch (ch)
{
case '/': case '*': return 2; case
'+': case '-': return 1; default:
return 0;
}
}
void infix2postfix(const char infix[], char postfix[], int size)
{
stack<char> s; int
weight;
int i = 0; int k
= 0; char ch;
while (i < size)
{
ch = infix[i]; if
(ch == '(') {
s.push(ch);
} else if (ch ==
')')
{
while (!s.empty() && s.top() != '(')
{
postfix[k++] = s.top();
s.pop();
}
if (!s.empty())
{
s.pop();
}
} else
{
weight = getWeight(ch); if
(weight == 0)
{
postfix[k++] = ch;
} else
{
while (!s.empty() && s.top() != '(' && weight <= getWeight(s.top()))
{
postfix[k++] = s.top();
s.pop();
}
s.push(ch);
}
} i++;
}
while (!s.empty())
{
postfix[k++] = s.top();
s.pop();
} postfix[k] = '\
0';
}
int main()
{
char infix[100]; cout << "Enter the Infix
Expression: "; cin >> infix; int size =
strlen(infix); char postfix[size + 1];
infix2postfix(infix, postfix, size); cout << "\
nInfix Expression: " << infix; cout << "\
nPostfix Expression: " << postfix; cout <<
endl; return 0;
}
OUTPUT:
Enter the Infix Expression: A*(B+C)/D
Infix Expression: A*(B+C)/D
Postfix Expression: ABC+*D/
Name: Dnyanraj Sonawane Roll no.:COSB69
Assignment No. 11
INPUT:
#include <iostream>
#include <string> class
JobQueue
{
std::string* queue; int front, rear,
maxSize, currentSize; public:
JobQueue(int size) : maxSize(size), front(0), rear(0), currentSize(0)
{
queue = new std::string[maxSize];
}
~JobQueue()
{
delete[] queue;
}
bool isFull() const
{
return currentSize == maxSize;
}
bool isEmpty() const
{
return currentSize == 0;
}
void addJob(const std::string& job)
{
if (isFull())
{
std::cout << "\nQueue is full ! Cannot add job.\n"; return;
}
queue[rear] = job; rear = (rear + 1) %
maxSize; currentSize++; std::cout <<
"Job added: " << job << "\n";
}
void deleteJob(const std::string& job)
{
if (isEmpty())
{
std::cout << "\nNo jobs to delete.\n"; return;
} for (int i = 0; i < currentSize; i+
+)
{
int index = (front + i) % maxSize; if
(queue[index] == job)
{
std::cout << "Job deleted: " << queue[index] << "\n";
for (int j = i; j < currentSize - 1; j++) { queue[(front + j) %
maxSize] = queue[(front + j + 1) % maxSize]; }
OUTPUT:
Enter maximum number of jobs: 3
1. Add Job
2. Delete Job
3. Display Jobs
Enter your choice: 1
Enter job description: Data Analyst
Job added: Data Analyst
1. Add Job
2. Delete Job
3. Display Jobs
Enter your choice: 1 Enter job
description: System Designer
Queue is full ! Cannot add job.
1. Add Job
2. Delete Job
3. Display Jobs
Choice: 1 Enter
element: 2
Inserted 2 at the front.
Choice: 2 Enter
element: 3
Inserted 3 at the rear.
Choice: 2 Enter
element: 4
Inserted 4 at the rear.
Enter your choice:-
1. Add Front
2. Add Rear
3. Delete Front
4. Delete Rear
5. Display
Choice: 5
Dequeue elements: 4 3 1 2
Choice: 3
Deleted 2 from the front.
Choice: 4
Deleted 4 from the rear.
Choice: 5
Dequeue elements: 3 1
Choice: 4
Deleted 3 from the rear.
Choice: 4
Deleted 1 from the rear.
Enter your choice:-
1. Add Front
2. Add Rear
3. Delete Front
4. Delete Rear
5. Display
Choice: 5
Dequeue is empty !
OUTPUT:
Enter maximum number of orders: 3
1. Place Order
2. Serve Order
3. Display Orders
Enter your choice: 1
Enter the order description: Margherita Pizza
Order Placed: Margherita Pizza
Veggie Pizza
1. Place Order
2. Serve Order
3. Display Orders
Enter your choice: 2
Serving Order: Margherita Pizza