-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.c
73 lines (63 loc) · 897 Bytes
/
queue.c
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
/*
*
* description:
*
* author: Chaitanya Borah
*
* creation time: Sat Feb 27 19:56:35 2016
*
*
*/
#include"sh_header.h"
extern unsigned int count;
void enqueue(Q_NODE **hptr, char *cmd)
{
Q_NODE *temp=malloc(sizeof(Q_NODE)),*q=*hptr;
/*Filling up the members*/
temp->serial_no=count;
strcpy(temp->stored_command,cmd);
/*If queue is empty*/
if(*hptr==0)
{
*hptr=temp;
temp->next=0;
}
/*moves towards the end and add node*/
else
{
while(q->next)
{
q=q->next;
}
q->next=temp;
temp->next=0;
}
}
void dequeue(Q_NODE** hptr)
{
Q_NODE* temp=*hptr;
*hptr=(*hptr)->next;
free(temp);
}
void show_command_history(Q_NODE* p)
{
if(p==0)
{
printf("hist: No history\n");
}
while(p)
{
printf("%d: %s\n",p->serial_no,p->stored_command);
p=p->next;
}
}
int count_node(Q_NODE *p)
{
unsigned int c=0;
while(p)
{
p=p->next;
c++;
}
return c;
}