A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d8/db7/queue__using__linked__list_8cpp_source.html below:

TheAlgorithms/C++: data_structures/queue_using_linked_list.cpp Source File

Loading...

Searching...

No Matches

queue_using_linked_list.cpp

1#include <iostream> 2using namespace

std;

3 4struct node

{

5 int

val;

6 node

*next;

7

};

8 9node

*front, *rear;

10 11void

Enque(

int

x) {

12 if

(rear == NULL) {

13 node

*n =

new node

;

14

n->val = x;

15

n->next = NULL;

16

rear = n;

17

front = n;

18

}

19 20 else

{

21 node

*n =

new node

;

22

n->val = x;

23

n->next = NULL;

24

rear->next = n;

25

rear = n;

26

}

27

}

28 29void

Deque() {

30 if

(rear == NULL && front == NULL) {

31

cout <<

"\nUnderflow"

;

32

}

else

{

33 node

*t = front;

34

cout <<

"\n"

<< t->val <<

" deleted"

;

35

front = front->next;

36 delete

t;

37 if

(front == NULL)

38

rear = NULL;

39

}

40

}

41 42void

show() {

43 node

*t = front;

44 while

(t != NULL) {

45

cout << t->val <<

"\t"

;

46

t = t->next;

47

}

48

}

49 50int main

() {

51 int

ch, x;

52 do

{

53

cout <<

"\n1. Enque"

;

54

cout <<

"\n2. Deque"

;

55

cout <<

"\n3. Print"

;

56

cout <<

"\nEnter Your Choice : "

;

57

cin >> ch;

58 if

(ch == 1) {

59

cout <<

"\nInsert : "

;

60

cin >> x;

61

Enque(x);

62

}

else if

(ch == 2) {

63

Deque();

64

}

else if

(ch == 3) {

65

show();

66

}

67

}

while

(ch != 0);

68 69 return

0;

70

}

node

struct node { int data; int height; struct node *left; struct node *right;} node

for std::queue

Definition avltree.cpp:13 main

int main()

Main function.

Definition generate_parentheses.cpp:110 node Definition binary_search_tree.cpp:11

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4