ChartGPT - DATA STRUCTURES LA1
ChartGPT - DATA STRUCTURES LA1
ChartGPT - DATA STRUCTURES LA1
#include <stdio.h>
int fibonacci(int n) {
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}
int main() {
int n, i;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci series: ");
for (i = 0; i < n; i++) {
printf("%d ", fibonacci(i));
}
printf("\n");
return 0;
}
int main() {
char str1[100], str2[100];
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
int main() {
char str1[100], str2[100];
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
4. Use pointers to copy a string and extract a substring from a given string.
#include <stdio.h>
int main() {
char str[100], copy[100], sub[100];
int start, len;
stringCopy(str, copy);
printf("Copied string: %s\n", copy);
return 0;
}
#include <stdio.h>
int main() {
int n, i, max, min, arr[100];
return 0;
}
#include <stdio.h>
int main() {
int n, i, pos, arr[100];
return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
int main() {
struct Node *head = NULL, *temp, *newNode;
int n, i, data;
if (head == NULL)
head = newNode;
else {
temp = head;
while (temp->next != NULL)
temp = temp->next;
temp->next = newNode;
}
}
display(head);
return 0;
}
int main() {
int n, i, arr[100];
insertionSort(arr, n);
return 0;
}
#include <stdio.h>
int main() {
int n, i, arr[100];
selectionSort(arr, n);
return 0;
}
struct Node {
int data;
struct Node* next;
};
int main() {
struct Node* head = NULL;
int data;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
if (temp == NULL)
return;
prev->next = temp->next;
free(temp);
}
int main() {
struct Node *head = NULL, *temp, *newNode;
int data, n, key;
return 0;
}
struct Stack {
int data;
struct Stack* next;
};
int main() {
struct Stack* top = NULL;
push(&top, 10);
push(&top, 20);
push(&top, 30);
printf("Stack: ");
display(top);
printf("Popped element: %d\n", pop(&top));
printf("Stack after pop: ");
display(top);
return 0;
}
int main() {
int n, arr[100], x, result;
return 0;
}
struct Queue {
int data;
struct Queue* next;
};
int dequeue() {
if (front == NULL) {
printf("Queue Underflow\n");
return -1;
}
struct Queue* temp = front;
front = front->next;
if (front == NULL)
rear = NULL;
int data = temp->data;
free(temp);
return data;
}
void display() {
struct Queue* temp = front;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
int main() {
enqueue(10);
enqueue(20);
enqueue(30);
printf("Queue: ");
display();
return 0;
}
return 0;
}