Skip to content

Commit

Permalink
second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sujalsrichandan2003 committed Oct 2, 2023
1 parent ce30aac commit 43b4b19
Show file tree
Hide file tree
Showing 21 changed files with 738 additions and 0 deletions.
82 changes: 82 additions & 0 deletions 6,1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <stdio.h>
#include <stdlib.h>

typedef struct Node
{
int data;
struct Node *prev;
struct Node *next;
} Node;

Node *head = NULL;

Node *createNode(int data)
{
Node *newNode = (Node *)malloc(sizeof(Node));
newNode->data = data;
newNode->prev = NULL;
newNode->next = NULL;
return newNode;
}

void insertNode(int data, int position)
{
Node *newNode = createNode(data);

if (head == NULL || position == 1)
{
newNode->next = head;
head = newNode;
if (head->next != NULL)
{
head->next->prev = newNode;
}
}
else
{
Node *temp = head;
int i = 1;
while (i < position - 1 && temp != NULL)
{
temp = temp->next;
i++;
}

if (temp == NULL)
{
printf("Invalid position\n");
return;
}

newNode->next = temp->next;
newNode->prev = temp;
temp->next = newNode;
if (newNode->next != NULL)
{
newNode->next->prev = newNode;
}
}
}

void displayList()
{
Node *temp = head;
while (temp != NULL)
{
printf("%d <-> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}

int main()
{
insertNode(10, 1);
insertNode(20, 2);
insertNode(30, 3);
insertNode(40, 4);

displayList();

//    return 0;
}
Binary file added 6,1.exe
Binary file not shown.
85 changes: 85 additions & 0 deletions CW(7,1).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <stdio.h>
#include <stdlib.h>

struct p
{
int data;
struct p *add;
};

struct p *start = NULL, *temp, *new1, *next, *prev;
void creat();
void display();
void insert_frist();
void insert_last();
void main()
{
int n;
printf("----------------linked list-------------\n");
do
{
printf("1.craet\n2.dispaly\n3.exit\n");
scanf("%d", &n);
switch (n)
{
case 1:
creat();
break;
case 2:
display();
break;
}
} while (n != 3);
}

void creat()
{
char ch;
int n;
printf("enter a element=");
scanf("%d", &n);
start = (struct p *)(malloc(sizeof(struct p)));
start->data = n;
start->add = NULL;
temp = start;

printf("want to cuntinue (yes or no)\n");
scanf(" %c", &ch);
while (ch == 'Y' || ch == 'y')
{
printf("entre a next elment =");
scanf("%d", &n);
new1 = (struct p *)(malloc(sizeof(struct p)));
new1->data = n;
new1->add = NULL;
temp->add = new1;
temp = temp->add;
printf("want to cuntinue 1 (yes or no)\n");
scanf("%c", &ch);
scanf(" %c", &ch);
ch=getche();
printf("\n");
}
}

void display()
{
int count = 0;
if (start == NULL)
{
printf("list ist not found");
}
else
{
temp = start;
while (temp != NULL)
{
if (temp->data != 0) {
count++;}
temp = temp->add;
}

printf("The number of non-zero elements in the linked list is: %d\n", count);

    }
}
Binary file added DS(1,2).exe
Binary file not shown.
50 changes: 50 additions & 0 deletions DS(2,4).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <stdio.h>

char grade(int marks) {
if (marks > 90)
return 'O';
else if (marks > 80)
return 'E';
else if (marks > 70)
return 'A';
else if (marks > 60)
return 'B';
else
return 'F';
}

int main() {
int n;
printf("Enter number of classes:");
scanf("%d", &n);

for (int i = 0; i < n; i++) {

int sub;
printf("Enter the total number of subjects in class %d:", i + 1);
scanf("%d", &sub);
int students;
printf("Enter number of students in class %d:", i + 1);
scanf("%d", &students);

int marks[students][sub];
for (int j = 0; j < students; j++) {
printf("Enter marks of student %d:\n", j + 1);
for (int k = 0; k < sub; k++) {
printf("Enter marks in subject %d:", k + 1);
scanf("%d", &marks[j][k]);
}
}
printf("\n");

printf("Class number %d:\n", i + 1);
for (int j = 0; j < students; j++) {
printf("Marks of student number %d:\n", j + 1);
for (int k = 0; k < sub; k++) {
printf("Grade of student in sub %d: %c\n", k + 1, grade(marks[j][k]));
}
}
}
return 0;
}

Binary file added DS(2,4).exe
Binary file not shown.
Binary file modified DS(3,1).exe
Binary file not shown.
Binary file modified DS(3,4).exe
Binary file not shown.
121 changes: 121 additions & 0 deletions DS(4,1).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//#include<stdio.h>
//#define n 10
//int queue[n];
//int front = -1;
//int rear = -1;
//
//void insert(int x)
//{
// if (rear==n-1)
// {
// printf("queue is full \n");
// }
// else if(front==-1 && rear==-1)
// {
// front=rear=0;
// queue[rear]=x;
// }
//}
//
//void delet()
//{
// if(front==-1 && rear==-1)
// {
// printf("queue is empty \n");
// }
// else if(front==rear)
// {
// // printf("%d",queue[front]);
// front=rear=-1;
// }
// else
// {
// front++;
// }
//}
//
//void display()
//{
// int i;
// if(front==-1 && rear==-1)
// {
// printf("queue is empty \n");
// }
// else
// {
// for(i=front;i<rear+1,i++;)
// {
// printf("%d",queue[i]);
// }
// }
//}
//
//int main()
//{
// printf("insert number:\n");
// insert(1);
// insert(6);
// insert(9);
// //delet();
// insert(5);
// insert(7);
// insert(8);
// //delet();
// display();
//}

#include<stdio.h>
# define max 10
int queue[max];
int front = -1;
int rear = -1;
int insert(int ele){
if (rear == max - 1)
{
printf("Queue is full\n");
}
if (front == -1)
front = 0;
rear++;
queue[rear] = ele;
printf("The inserted element is %d\n",ele);

}
int delt()
{
int item;
if (front == -1 || front > rear)
{
printf("Queue is empty\n");
return -1;
}
item = queue[front];
front++;
return item;
}
void display()
{
int i;
if (front == -1 && front > rear)
{
printf("Queue is empty\n");
return;
}
printf("The queue elements are:\n");
for (i = front; i <= rear; i++)
printf("%d\n", queue[i]);

}
int main(){
printf("insert numbers: \n");
insert(1);
insert(6);
insert(9);
delt();
insert(5);
insert(7);
insert(8);
delt();
display();
}

Binary file added DS(4,1).exe
Binary file not shown.
54 changes: 54 additions & 0 deletions DS(4,2).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include<stdio.h>
# define max 10
int queue[max];
int front = -1;
int rear = -1;
int cqinsert(int ele){
if (rear == max - 1)
{
printf("Queue is full\n");
}
if (front == -1)
front = 0;
rear++;
queue[rear % max] = ele;
printf("The inserted element is %d\n",ele);

}
int cqdelt()
{
int item;
if (front == -1 || front > rear)
{
printf("Queue is empty\n");
return -1;
}
item = queue[front];
front=(front+1)%max;
return item;
}
void display()
{
int i;
if (front == -1 && front > rear)
{
printf("Queue is empty\n");
return;
}
printf("The queue elements are:\n");
for (i = front; i <= rear; i++)
printf("%d\n", queue[i]);

}
int main(){
printf("insert numbers: \n");
cqinsert(1);
cqinsert(6);
cqinsert(9);
cqdelt();
cqinsert(5);
cqinsert(7);
cqinsert(8);
cqdelt();
display();
}
Binary file added DS(4,2).exe
Binary file not shown.
Loading

0 comments on commit 43b4b19

Please sign in to comment.