You are on page 1of 2

QUESTION 2

Struct Node {

Char day[10] ;

Struct Node* prev ;

Struct Node* next ;

};

Struct Node* head = NULL ;

Void insertAtBeginning(char* day) {

Struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)) ;

Strcpy(newNode->day, day) ;

newNode->prev = NULL ;

newNode->next = head ;

if (head != NULL) {

head->prev = newNode ;

Head = newNode ;

Void insertAtEnd(char* day) {

Struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)) ;

Strcpy(newNode->day, day) ;

newNode->next = NULL ;

if (head == NULL) {

newNode->prev = NULL ;

head = newNode ;

return ;

Struct Node* currNode = head ;

While (currNode->next != NULL) {

currNode = currNode->next ;

currNode->next = newNode ;
newNode->prev = currNode ;

Void printList() {

Struct Node* currNode = head ;

Printf(« Liste : « ) ;

While (currNode != NULL) {

Printf(« %s « , currNode->day) ;

currNode = currNode->next ;

Printf(« \n ») ;

Int main() {

insertAtEnd(« Lundi ») ;

insertAtEnd(« Mardi ») ;

insertAtEnd(« Mercredi ») ;

insertAtBeginning(« Dimanche ») ;

insertAtBeginning(« Samedi ») ;

printList() ;

return 0 ;

You might also like