Question: A double-ended queue implemented as a doubly-linked list may be defined as shown below on lines 4-21. The function declared on lines 23-53 creates a

A double-ended queue implemented as a doubly-linked list may be defined as shown below on lines 4-21. The function declared on lines 23-53 creates a new deque (pointed at by rp) containing every data item from the deque d (starting with its last) but in the opposite order to the way they are stored in d.

There are, unfortunately, six lines in the reverse() function with errors. can someone find the line number on which each error occurs and re-write the line explaining it.

1 #include

2 #include

3

4 struct dnode_int;

5 typedef struct dnode_int* dnode;

6

7 struct dnode_int

8 {

9 dnode prev;

10 void* data;

11 dnode next;

12 };

13

14 struct deque_int;

15 typedef struct deque_int* deque;

16

17 struct deque_int

18 {

19 dnode first;

20 dnode last;

21 };

22

23 void reverse(deque* rp, deque d)

24 {

25 dnode rc = NULL;

26 dnode dc = d->first;

27 dnode n;

28

29 (*rp) = (deque)malloc(sizeof(deque));

30 (*rp)->first = NULL;

31 (*rp)->last = NULL;

32

33 while (dc != NULL)

34 {

35 n = (dnode)malloc(sizeof(dnode));

36 n->data = NULL;

37 n->prev = NULL;

38 n->next = NULL;

39

40 if ((*rp)->first != NULL)

41 {

42 (*rp)->first = n;

43 }

44 else

45 {

46 n->prev = rc;

47 rc->next = n;

48 }

49 rc = n->next;

50 dc = dc->prev;

51 }

52 (*rp)->last = rc;

53 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!