Double ended queue program in c language




















Initialize an array and pointers for deque 1. Insert at the Front This operation adds an element at the front. Check the position of front. Shift front to the end Else, decrease front by 1. Add the new key 5 into array[front]. Insert the element at Front 2. Insert at the Rear This operation adds an element to the rear. Check if the array is full. Else, increase rear by 1.

Increase the rear Add the new key 5 into array[rear]. Insert the element at rear 3. Delete from the Front. Previous Tutorial:. Next Tutorial:. Share on:. And to do insertion at the rear position, place the new node before the tail.

Similarly, dequeue operation can also be performed at the front and rear positions. Enqueue at front 2. Enqueue at rear 3. Dequeue at front 4.

Dequeue at rear 5. Display 6. Exit Enter your choice:1 Enter the data to insert 1. Exit Enter your choice:5 30 20 10 1. Exit Enter your choice:2 Enter ur data to insert 1. Exit Enter your choice:5 30 20 10 40 1. Your code is extremely hard to read, which makes it hard to concentrate a review on the specific points you want reviewed although I think that the general structure of your linked list is actually alright.

I would probably put data and link together in one class, but other than that it seems fine. When writing code, try to think about the people who are going to read it this might include you in the future.

I think you get the idea. It would be better if you would catch those exceptions, report the problem to the user, and ask for input again.



0コメント

  • 1000 / 1000