PROGRAMMING _ASSIGNMENT4
PROGRAMMING _ASSIGNMENT4
PROGRAMMING _ASSIGNMENT4
#include <stdlib.h>
#include <string.h>
struct Student {
char name[100];
};
strcpy(newStudent->name, name);
newStudent->next = newStudent;
return newStudent;
if (*head == NULL) {
*head = newStudent;
} else {
temp = temp->next;
temp->next = newStudent;
newStudent->next = *head;
if (head == NULL) {
return;
do {
temp = temp->next;
printf("(back to start)\n");
if (*head1 == NULL) {
*head1 = *head2;
return;
if (*head2 == NULL) {
return;
temp1 = temp1->next;
}
struct Student* temp2 = *head2;
temp2 = temp2->next;
temp1->next = *head2;
temp2->next = *head1;
*head2 = NULL;
int main() {
insertStudent(&undergraduateList, "Alice");
insertStudent(&undergraduateList, "Bob");
insertStudent(&undergraduateList, "Charlie");
insertStudent(&postgraduateList, "David");
insertStudent(&postgraduateList, "Eve");
printList(undergraduateList);
printList(postgraduateList);
concatenateLists(&undergraduateList, &postgraduateList);
printList(undergraduateList);
return 0;
#include <stdlib.h>
struct Node {
int digit;
};
newNode->digit = digit;
newNode->next = newNode;
return newNode;
if (*head == NULL) {
*head = newNode;
} else {
temp = temp->next;
temp->next = newNode;
newNode->next = *head;
if (head == NULL) {
return;
}
struct Node* temp = head;
do {
printf("%d", temp->digit);
temp = temp->next;
printf("\n");
int carry = 0;
do {
if (temp1 != NULL) {
sum += temp1->digit;
temp1 = temp1->next;
if (temp2 != NULL) {
sum += temp2->digit;
temp2 = temp2->next;
return result;
int main() {
insertDigit(&num1, 4);
insertDigit(&num1, 5);
insertDigit(&num2, 7);
insertDigit(&num2, 8);
insertDigit(&num2, 9);
printf("Number 1: ");
printList(num1);
printf("Number 2: ");
printList(num2);
printf("Sum: ");
printList(result);
return 0;
#include <stdlib.h>
struct Node {
int data;
};
struct Stack {
};
stack->top = NULL;
}
int isEmpty(struct Stack* stack) {
newNode->data = data;
if (stack->top == NULL) {
stack->top = newNode;
newNode->next = newNode;
} else {
temp = temp->next;
temp->next = newNode;
newNode->next = stack->top;
stack->top = newNode;
if (isEmpty(stack)) {
printf("Stack underflow\n");
return -1;
int data;
if (stack->top->next == stack->top) {
data = stack->top->data;
free(stack->top);
stack->top = NULL;
} else {
temp = temp->next;
data = stack->top->data;
temp->next = stack->top->next;
free(stack->top);
stack->top = temp->next;
return data;
if (isEmpty(stack)) {
printf("Stack is empty\n");
return -1;
return stack->top->data;
if (isEmpty(stack)) {
printf("Stack is empty\n");
return;
do {
temp = temp->next;
printf("\n");
int main() {
push(&stack, 10);
push(&stack, 20);
push(&stack, 30);
push(&stack, 40);
printf("Stack: ");
printStack(&stack);
printStack(&stack);
return 0;
#include <stdlib.h>
struct Node {
int data;
};
newNode->data = data;
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}
void insertAtEnd(struct Node** head, int data) {
if (*head == NULL) {
*head = newNode;
} else {
temp = temp->next;
temp->next = newNode;
newNode->prev = temp;
temp = temp->next;
printf("\n");
if (*head1 == NULL) {
*head1 = *head2;
return;
if (*head2 == NULL) {
return;
temp->next = *head2;
(*head2)->prev = temp;
int main() {
insertAtEnd(&list1, 1);
insertAtEnd(&list1, 2);
insertAtEnd(&list1, 3);
insertAtEnd(&list2, 4);
insertAtEnd(&list2, 5);
insertAtEnd(&list2, 6);
printf("List 1: ");
printList(list1);
printf("List 2: ");
printList(list2);
concatenateLists(&list1, &list2);
printList(list1);
return 0;
5. Assume that you are given two doubly linked lists containing
songs. Design and implement a C Program to Find common
songs from both the lists.
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
char song[100];
};
strcpy(newNode->song, song);
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
if (*head == NULL) {
*head = newNode;
} else {
temp = temp->next;
temp->next = newNode;
newNode->prev = temp;
temp = temp->next;
}
printf("NULL\n");
if (strcmp(temp1->song, temp2->song) == 0) {
temp2 = temp2->next;
temp1 = temp1->next;
int main() {
printf("List 1: ");
printList(list1);
printf("List 2: ");
printList(list2);
findCommonSongs(list1, list2);
return 0;