Skip to content

Commit 26c9a3e

Browse files
committed
Indentation
1 parent 983472e commit 26c9a3e

File tree

1 file changed

+117
-117
lines changed

1 file changed

+117
-117
lines changed

double_ended_queue/doubleEndedQueue.c

Lines changed: 117 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -3,153 +3,153 @@
33

44
struct Deque
55
{
6-
int data;
7-
struct Deque *next;
6+
int data;
7+
struct Deque *next;
88
};
99
struct Deque *head = NULL;
1010
struct Deque *last = NULL;
1111

12-
struct Deque *createDeque(struct Deque *root, int key) //Function to create deque
12+
struct Deque *createDeque(struct Deque *root, int key) //Function to create deque
1313
{
14-
root = (struct Deque *)malloc(sizeof(struct Deque));
15-
root->data = key;
16-
root->next = NULL;
17-
head = root;
18-
last = root;
19-
return head;
14+
root = (struct Deque *)malloc(sizeof(struct Deque));
15+
root->data = key;
16+
root->next = NULL;
17+
head = root;
18+
last = root;
19+
return head;
2020
}
2121

22-
struct Deque *push_front(struct Deque *root, int key) //Function to push element on the front of deque
22+
struct Deque *push_front(struct Deque *root, int key) //Function to push element on the front of deque
2323
{
24-
if (head == NULL)
25-
{
26-
return createDeque(root, key);
27-
}
28-
struct Deque *temp;
29-
temp = (struct Deque *)malloc(sizeof(struct Deque));
30-
temp->data = key;
31-
temp->next = head;
32-
head = temp;
33-
return head;
24+
if (head == NULL)
25+
{
26+
return createDeque(root, key);
27+
}
28+
struct Deque *temp;
29+
temp = (struct Deque *)malloc(sizeof(struct Deque));
30+
temp->data = key;
31+
temp->next = head;
32+
head = temp;
33+
return head;
3434
}
3535

36-
struct Deque *push_back(struct Deque *root, int key) //Function to push element to the back of deque
36+
struct Deque *push_back(struct Deque *root, int key) //Function to push element to the back of deque
3737
{
38-
if (head == NULL)
39-
{
40-
return createDeque(root, key);
41-
}
42-
struct Deque *temp;
43-
temp = (struct Deque *)malloc(sizeof(struct Deque));
44-
temp->data = key;
45-
temp->next = NULL;
46-
last->next = temp;
47-
last = temp;
48-
return last;
38+
if (head == NULL)
39+
{
40+
return createDeque(root, key);
41+
}
42+
struct Deque *temp;
43+
temp = (struct Deque *)malloc(sizeof(struct Deque));
44+
temp->data = key;
45+
temp->next = NULL;
46+
last->next = temp;
47+
last = temp;
48+
return last;
4949
}
5050

51-
struct Deque *pop_front() //Function to remove or pop the front element
51+
struct Deque *pop_front() //Function to remove or pop the front element
5252
{
53-
if (head == NULL)
54-
{
55-
printf("Deque is empty.\n");
56-
return head;
57-
}
58-
struct Deque *temp;
59-
temp = head;
60-
head = head->next;
61-
free(temp); //free the unwanted space
62-
return head;
53+
if (head == NULL)
54+
{
55+
printf("Deque is empty.\n");
56+
return head;
57+
}
58+
struct Deque *temp;
59+
temp = head;
60+
head = head->next;
61+
free(temp); //free the unwanted space
62+
return head;
6363
}
6464

65-
struct Deque *pop_back() //Function to remove element from back of deque
65+
struct Deque *pop_back() //Function to remove element from back of deque
6666
{
67-
if (head == NULL) //before removing element, checking whether the deque is empty or not
68-
{
69-
printf("Deque is empty\n");
70-
return head;
71-
}
72-
struct Deque *temp, *temp2;
73-
temp = head;
74-
while (temp->next != last)
75-
{
76-
temp = temp->next;
77-
}
78-
temp2 = temp->next;
79-
temp->next = NULL;
80-
last = temp;
81-
free(temp2); //free the unwanted space
82-
return head;
67+
if (head == NULL) //before removing element, checking whether the deque is empty or not
68+
{
69+
printf("Deque is empty\n");
70+
return head;
71+
}
72+
struct Deque *temp, *temp2;
73+
temp = head;
74+
while (temp->next != last)
75+
{
76+
temp = temp->next;
77+
}
78+
temp2 = temp->next;
79+
temp->next = NULL;
80+
last = temp;
81+
free(temp2); //free the unwanted space
82+
return head;
8383
}
8484

85-
void front() //Function to give the front element of deque
85+
void front() //Function to give the front element of deque
8686
{
87-
if (head == NULL)
88-
{
89-
printf("Deque is empty.\n\n");
90-
}
91-
printf("The element at the front of deque is %d.\n\n", head->data);
87+
if (head == NULL)
88+
{
89+
printf("Deque is empty.\n\n");
90+
}
91+
printf("The element at the front of deque is %d.\n\n", head->data);
9292
}
9393

94-
void back() //Function to give the back of deque
94+
void back() //Function to give the back of deque
9595
{
96-
if (head == NULL)
97-
{
98-
printf("Deque is empty\n");
99-
}
100-
printf("The element at the last of deque is %d.\n\n", last->data);
96+
if (head == NULL)
97+
{
98+
printf("Deque is empty\n");
99+
}
100+
printf("The element at the last of deque is %d.\n\n", last->data);
101101
}
102102

103-
void isEmpty() //Function to know whether deque is empty or not
103+
void isEmpty() //Function to know whether deque is empty or not
104104
{
105-
if (head == NULL)
106-
{
107-
printf("List is empty.\n\n");
108-
}
109-
else
110-
{
111-
printf("No, list is not empty.\n\n");
112-
}
105+
if (head == NULL)
106+
{
107+
printf("List is empty.\n\n");
108+
}
109+
else
110+
{
111+
printf("No, list is not empty.\n\n");
112+
}
113113
}
114114

115-
void displayTheDeque() //Function to print the whole deque
115+
void displayTheDeque() //Function to print the whole deque
116116
{
117-
if (head == NULL)
118-
{
119-
printf("Deque is empty.\n\n");
120-
}
121-
else
122-
{
123-
printf("The Deque is \n\t ");
124-
printf("Front-----> ");
125-
struct Deque *temp = head; //initializing the temporary pointer to head of deque
126-
while (temp != NULL)
127-
{
128-
printf("%d \t", temp->data);
129-
temp = temp->next;
130-
}
131-
printf(" <-----End\n\n");
132-
}
117+
if (head == NULL)
118+
{
119+
printf("Deque is empty.\n\n");
120+
}
121+
else
122+
{
123+
printf("The Deque is \n\t ");
124+
printf("Front-----> ");
125+
struct Deque *temp = head; //initializing the temporary pointer to head of deque
126+
while (temp != NULL)
127+
{
128+
printf("%d \t", temp->data);
129+
temp = temp->next;
130+
}
131+
printf(" <-----End\n\n");
132+
}
133133
}
134134
int main()
135135
{
136-
struct Deque *root = NULL;
137-
root = createDeque(root, 4); //creating Deque
138-
push_front(root, 6); //pushing data on the front
139-
push_back(root, 5); //pushing data on the back
140-
push_front(root, 61);
141-
push_front(root, 6);
142-
push_front(root, 12);
143-
push_front(root, 60);
144-
push_back(root, 68);
145-
displayTheDeque(); //Displaying the deque
146-
pop_front(); //removing front element
147-
printf("After removing from front, ");
148-
displayTheDeque();
149-
pop_back(); //removing back element
150-
printf("After removing from back, ");
151-
displayTheDeque();
152-
front(); //Getting value of front element of deque
153-
back(); //Getting value of back element of deque
154-
isEmpty(); //Checking if deque is empty or not
136+
struct Deque *root = NULL;
137+
root = createDeque(root, 4); //creating Deque
138+
push_front(root, 6); //pushing data on the front
139+
push_back(root, 5); //pushing data on the back
140+
push_front(root, 61);
141+
push_front(root, 6);
142+
push_front(root, 12);
143+
push_front(root, 60);
144+
push_back(root, 68);
145+
displayTheDeque(); //Displaying the deque
146+
pop_front(); //removing front element
147+
printf("After removing from front, ");
148+
displayTheDeque();
149+
pop_back(); //removing back element
150+
printf("After removing from back, ");
151+
displayTheDeque();
152+
front(); //Getting value of front element of deque
153+
back(); //Getting value of back element of deque
154+
isEmpty(); //Checking if deque is empty or not
155155
}

0 commit comments

Comments
 (0)