Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions QueueClass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include<iostream>
using namespace std;
class Queue {
private:
node* front;
node* rear;

public:
Queue() {
front = NULL;
rear = NULL;
}
void joinQueue(int Id);
void serveCompleted(vector<Agent>& agents);
void showQueue();
};
void Queue::joinQueue(int Id) {
node* newUser = new node(Id);
if (rear == NULL) {
front = rear = newUser;
} else {
rear->next = newUser;
rear = newUser;
}
cout << "User " << Id << " joined the queue.\n";
}
void Queue::serveCompleted(vector<Agent>& agents) {
if (front == NULL) {
cout << "No users in queue.\n";
return;
}
for (auto& agent : agents) {
if (agent.isAvailable) {
node* temp = front;
front = front->next;
if (front == NULL) rear = NULL;

agent.isAvailable = false;

cout << "Agent " << agent.ID << " is now serving User " << temp->userID << "\n";
delete temp;
return;
}
}
cout << "No available agents at the moment. Please wait.\n";
}

void Queue::showQueue() {
if (front == NULL) {
cout << "Queue is empty.\n";
return;
}

cout << "Current Queue: ";
node* temp = front;
while (temp != NULL) {
cout << temp->userID << " ";
temp = temp->next;
}
cout << "\n";
}

24 changes: 19 additions & 5 deletions agentNode.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
#include<iostream>
using namespace std;
class Agent{
private:
int ID;
node* next;
public:
int ID;
bool isAvailable;
Agent(int id){
ID = id;
next = NULL;
isAvailable = true;
}
};
};

void releaseAgent(vector<Agent>& agents, int agentId) {
for (auto& agent : agents) {
if (agent.ID == agentId) {
if (!agent.isAvailable) {
agent.isAvailable = true;
cout << "Agent " << agent.ID << " is now available.\n";
} else {
cout << "Agent " << agent.ID << " is already available.\n";
}
return;
}
}
cout << "Agent ID not found.\n";
}
152 changes: 152 additions & 0 deletions code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class node{
public:
int userID;
node* next;
node(int id){
userID = id;
next = NULL;
}
};
class Agent{
public:
int ID;
bool isAvailable;
Agent(int id){
ID = id;
isAvailable = true;
}
};



class Queue {
private:
node* front;
node* rear;

public:
Queue() {
front = nullptr;
rear = nullptr;
}
void joinQueue(int Id);
void serveCompleted(vector<Agent>& agents);
void showQueue();
};
void Queue::joinQueue(int Id) {
node* newUser = new node(Id);
if (rear == nullptr) {
front = rear = newUser;
} else {
rear->next = newUser;
rear = newUser;
}
cout << "User " << Id << " joined the queue.\n";
}
void Queue::serveCompleted(vector<Agent>& agents) {
if (front == NULL) {
std::cout << "No users in queue.\n";
return;
}
for (auto& agent : agents) {
if (agent.isAvailable) {
node* temp = front;
front = front->next;
if (front == NULL) rear = NULL;

agent.isAvailable = false;

cout << "Agent " << agent.ID<< " is now serving User " << temp->userID << "\n";
delete temp;
return;
}
}
cout << "No available agents at the moment. Please wait.\n";
}

void Queue::showQueue() {
if (front == NULL) {
cout << "Queue is empty.\n";
return;
}

cout << "Current Queue: ";
node* temp = front;
while (temp != nullptr) {
cout << temp->userID << " ";
temp = temp->next;
}
cout << "\n";
}




void releaseAgent(vector<Agent>& agents, int agentId) {
for (auto& agent : agents) {
if (agent.ID == agentId) {
if (!agent.isAvailable) {
agent.isAvailable = true;
cout << "Agent " << agent.ID<< " is now available.\n";
} else {
cout << "Agent " << agent.ID << " is already available.\n";
}
return;
}
}
cout << "Agent ID not found.\n";
}



int main() {
Queue chatQueue;
int choice, Id = 1;
int numAgents;

cout << "Enter number of agents: ";
cin >> numAgents;

vector<Agent> agents;
for (int i = 1; i <= numAgents; ++i) {
agents.push_back(Agent(i));
}

while (true) {
cout << "\n--- Chat Queue Menu ---\n";
cout << "1. New user joins\n";
cout << "2. Serve next user\n";
cout << "3. Release agent\n";
cout << "4. Show queue\n";
cout << "5. Exit\n";
cout << "Enter choice: ";
cin >> choice;

switch (choice) {
case 1:
chatQueue.joinQueue(Id++);
break;
case 2:
chatQueue.serveCompleted(agents);
break;
case 3: {
int Id;
cout << "Enter Agent ID to release: ";
cin >> Id;
releaseAgent(agents, Id);
break;
}
case 4:
chatQueue.showQueue();
break;
case 5:
return 0;
default:
std::cout << "Invalid choice.\n";
}
}
}
52 changes: 47 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
#include<iostream>
using namespace std;
int main(){
cout<<"DS project"<<endl;
}
int main() {
Queue chatQueue;
int choice, Id = 1;
int numAgents;

cout << "Enter number of agents: ";
cin >> numAgents;

vector<Agent> agents;
for (int i = 1; i <= numAgents; ++i) {
agents.push_back(Agent(i));
}

while (true) {
cout << "\n--- Chat Queue Menu ---\n";
cout << "1. New user joins\n";
cout << "2. Serve next user\n";
cout << "3. Release agent\n";
cout << "4. Show queue\n";
cout << "5. Exit\n";
cout << "Enter choice: ";
cin >> choice;

switch (choice) {
case 1:
chatQueue.joinQueue(Id++);
break;
case 2:
chatQueue.serveCompleted(agents);
break;
case 3: {
int Id;
cout << "Enter Agent ID to release: ";
cin >> Id;
releaseAgent(agents, Id);
break;
}
case 4:
chatQueue.showQueue();
break;
case 5:
return 0;
default:
cout << "Invalid choice.\n";
}
}
}
11 changes: 5 additions & 6 deletions queueNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
#include<string>
using namespace std;
class node{
private:
string userName;
node* next;
public:
node(string name){
userName = name;
int userID;
node* next;
node(int id){
userID = id;
next = NULL;
}
}
};
4 changes: 3 additions & 1 deletion text2.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
second day of ds project
agent node created
third day working on project
third day working on project
fourth day
fifth day yestarday commit not completed