Professional Documents
Culture Documents
DS Practicels
DS Practicels
Date: /08/23
OUTPUT:-
You have to Enter 10 integers
Enter: 2
Enter: 5
Enter: 6
Enter: 8
Enter: 5
Enter: 3
Enter: 1
Enter: 5
Enter: 6
Enter: 9
Displaying integers: 2 5 6 8 5 1 5 6 9
OUTPUT:-
Original array: Divya Mathankar
Array in reverse order: raknahtaM ayviD
int main()
{
int array[50], position, c, n, value;
printf("Enter number of elements in the array\n");
scanf("%d", &n);
array[position-1] = value;
return 0;
}
OUTPUT:-
Enter number of elements in the array
5
Enter 5 elements
6
7
8
9
10
Please enter the location where you want to insert an new element
3
Please enter the value
5
Resultant array is
6
7
5
8
9
10
int main ()
{
int arr[50];
int pos, i, num;
printf (" \n Enter the number of elements in an array: \n ");
scanf (" %d", &num);
int main()
{
return 0;
}
OUTPUT:-
#include <stdio.h>
int main()
{// WAP to print the Fibonacci series of the first 15 elements.
int a = 0, b = 1, c;
printf(" Q1. by Deepanshi\n");
printf("The first 15 elements of the Fibonacci series are:\n");
printf("%d %d ", a, b);
for (int i = 0; i < 13; i++)
{
c = a + b;
printf("%d ", c);
a = b;
b = c;
}
printf("\n");
OUTPUT:-
Q1. by Divya Mathankar
The first 15 elements of the Fibonacci series are:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
Q2. by Divya Mathankar
The 3x3 matrix is:
123
456
789
Q3. by Divya Mathankar
The sum of the two matrices is:
68
10 12
Q4. by Divya Mathankar
The transpose of the given matrix is:
147
258
369
DATA STRUCTURES LAB-3
DATE: /09/23
if(head == NULL) {
printf("List is empty\n");
return;
}
printf("Nodes of singly linked list: \n");
while(current != NULL) {
//Prints each node by incrementing pointer
printf("%d ", current->data);
current = current->next;
}
printf("\n");
}
int main()
{
//Add nodes to the list
addNode(1);
addNode(2);
addNode(3);
addNode(4);
OUTPUT:-
by Divya Mathankar
Enter the item which you want to insert?
5
Node inserted
int main() {
struct node* head = NULL;
return 0;
}
OUTPUT:-
Nodes of the linked list: 1 2 3 4 5
Node deleted from the beginning
Nodes of the linked list: 2 3 4 5
DATA STRUCTURES LAB-4
DATE: /09/23
OUTPUT:-
Element 1 pushed onto the stack
Element 2 pushed onto the stack
Element 3 pushed onto the stack
Elements of the stack: 3 2 1
Element 3 popped from the stack
Popped element: 3
Elements of the stack: 2 1
Top element: 2
Q.2)WAP to print your name in reverse order using
pop operation of stack.
// Divya Mathankar
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_SIZE 100
typedef struct { // Structure to represent a stack
char data[MAX_SIZE];
int top;
} Stack;
// Function to initialize the stack
void initialize(Stack *stack) {
stack->top = -1;
}
// Function to push an element onto the stack
void push(Stack *stack, char element) {
if (stack->top == MAX_SIZE - 1) {
printf("Stack Overflow\n");
return;
}
stack->data[++stack->top] = element;
}
// Function to pop an element from the stack
char pop(Stack *stack) {
if (stack->top == -1) {
printf("Stack Underflow\n");
return '\0';
}
return stack->data[stack->top--];
}
// Function to print a string in reverse order using a stack
void printReverseName(char *name) {
Stack stack;
initialize(&stack);
// Push each character of the name onto the stack
int length = strlen(name);
for (int i = 0; i < length; i++) {
push(&stack, name[i]);
}
// Pop and print each character from the stack
printf("Reversed name: ");
while (stack.top != -1) {
printf("%c", pop(&stack));
}
printf("\n");
}
int main() {
char name[100];
printf("Enter your name: ");
fgets(name, sizeof(name), stdin);
// Remove the newline character from the input
name[strcspn(name, "\n")] = '\0';
printReverseName(name);
return 0;
}
OUTPUT:-
Enter your name: Divya Mathankar
Reversed name: raknahtaM ayviD
DATA STRUCTURES LAB-5
Date: /09/23
if (front == rear){
printf("Queue is empty\n");
return -1;
}
if (rear==1){
rear--; front--;
} else {
rear--;
}
return element;
}
void display_queue(int queue[], int front, int rear){
if (front == rear){
printf("Queue is empty \n");
return;
}
for (int i = front; i <= rear; i++){
printf("%d \n", queue[i]);
}
printf("\n");
}
int main(){
enqueue(7);
enqueue(8);
enqueue(9);
enqueue(6);
display_queue(queue, front, rear);
// Dequeue the front element.
int element = dequeue(queue, front, rear);
if (element != -1){
printf("Element dequeued: %d\n", element);
}
display_queue(queue, front, rear);
printf("by Divya Mathankar");
return 0;
}
OUTPUT:-
7
8
Element dequeued: 7
by Divya Mathankar