-
Notifications
You must be signed in to change notification settings - Fork 12
/
phonelog queue.cpp
86 lines (85 loc) · 1.49 KB
/
phonelog queue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
struct Node
{
string data;
string name;
string t;
struct Node *next;
};
struct Node*front=NULL;
struct Node *rear=NULL;
void enqueue(string y,string w,string x)
{
struct Node *temp;
temp=new Node;
if(temp==NULL)
cout<<"Queue is FUll\n";
else
{
temp->data=x;
temp->name=y;
temp->t=w;
temp->next=NULL;
if(front==NULL)
front=rear=temp;
else
{
rear->next=temp;
rear=temp;
}
}
}
void dequeue()
{
struct Node* temp;
if(front==NULL)
cout<<"NO Call Log";
else
{
temp=front;
front=front->next;
free(temp);
}
}
void display(Node *temp)
{
if (temp == NULL)
return;
display(temp->next);
cout<<temp->name<<" "<<temp->data<<" "<<temp->t<<endl;
cout<<endl;
}
int main()
{
int n,count =0;
string x,w;
string y;
time_t now = time(0);
do
{ cout<<"enter 1 for input"<<endl<<"enter 2 for output"<< endl<<"Enter 0 to exit"<<endl;
cin>>n;
switch(n)
{ case 1:
if(count >=10)
dequeue();
cout<<"Enter Name: ";
cin>>x;
cout<<"Enter Phone number :";
cin>>y;
w = ctime(&now);
enqueue(x,w,y);
count++;
break;
case 2:
if(count==0)
cout<<"No Call Log"<<endl;
cout<<"Name\t"<<"Phone number\t\t"<<"date and time"<<endl;
display(front);
break;
}
}while(n!=0);
return 0;
}