Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Linked List Deque Implementation in C, Exams of Data Structures and Algorithms

A worksheet on implementing a linked list deque using c programming language. It includes the structure definition, function prototypes, and function implementations for various operations such as initialization, destruction, adding elements at the front and back, and removing elements from the front and back. The document also encourages readers to explore the use of a single sentinel value for both the front and back of the deque, resulting in a circular queue.

Typology: Exams

Pre 2010

Uploaded on 08/30/2009

koofers-user-tdw
koofers-user-tdw 🇺🇸

10 documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Linked List Deque Implementation in C and more Exams Data Structures and Algorithms in PDF only on Docsity! Worksheet 11: Linked List Deque Name: An Active Learning Approach to Data Structures using C 1 Worksheet 11: Linked List Deque In this lesson and the following we will develop a reasonably complete linked list abstraction. Our list will use sentinels on both the front and the back of the list, and double links. In this lesson we will emphasize the deque aspects of the list. In the following lesson we will add more operations. A deque, you recall, allows insertions at both the beginning and the end of the container. The interface is shown at right. Sentinels ensure the list is never completely empty. They also mean that all instructions can be described as special cases of more general routines. One of these, removeLink, you developed in the previous lesson. Another internal routine, addBefore, can be described as “insert a new link immediate before an existing link”. Write this new routine, and then show how all insertions can be handled by this one routine. As you add and remove elements make sure you keep the value of the size field up to date. When a value is removed from a list make sure you free the associated link fields. Use an assertion to check that allocations of new links are successful, and that you do not attempt to remove a value from an empty list. Finish the implementation of the LinkedList based on these ideas: backSentinel frontSentinel sentinel 7 4 Sentinel struct list { int size; struct dlink *frontSentinel; struct dlink *backSentinel; }; void listInit (struct list *lst); void listDestroy (struct list *lst); void listAddFront (struct list *lst, EleType d); void listAddBack (struct list *lst, EleType d); void listRemoveFront (struct list *lst); void listRemoveBack (struct list *lst); EleType listFront (struct list *lst); EleType listBack (struct list *lst); int listSize (struct list *lst); Worksheet 11: Linked List Deque Name: An Active Learning Approach to Data Structures using C 2 void listInit (struct list *lst); { } void listDestroy (struct list *lst) { } void listAddBefore (struct dlink * lnk, EleType d) { } void listAddFront (struct list *lst, EleType d) { } void listAddBack (struct list *lst, EleType d) { } void listRemoveFront (struct list *lst) { }
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved