0% found this document useful (0 votes)
23 views7 pages

Week 4 Hard

The document contains a coding assessment for a student named Phani Kumar, focusing on circular linked list applications in C programming. It includes problem statements, coding tasks, and the student's submitted code, which was evaluated with a score of 10 out of 20. The document also outlines the student's personal details, such as email, roll number, and department.

Uploaded by

Phani Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views7 pages

Week 4 Hard

The document contains a coding assessment for a student named Phani Kumar, focusing on circular linked list applications in C programming. It includes problem statements, coding tasks, and the student's submitted code, which was evaluated with a score of 10 out of 20. The document also outlines the student's personal details, such as email, roll number, and department.

Uploaded by

Phani Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PVPSIT Colab

P3

P3

P3
5P

05

05

05
A0

1A

1A

1A
01

50

50

50
Name: PHANI KUMAR Scan to verify results
5
24

24

24

24
Email: [email protected]
Roll no: 24501A05P3
Phone: 9959165989
Branch: PVPSIT Colab
Department: 2028 - CSE - S4
Batch: 2028
Degree: B.Tech - CSE
P3

P3

P3

3
5P
05

05

05

0
2024_28_II_CSE_S4_DS using C_Lab Assessment
1A

1A

1A

1A
50

50

50

50
24

24

24

24
PVPSIT_DSA_Lab 4_Linked List Applications_COD_Hard

Attempt : 1
Total Mark : 20
Marks Obtained : 10

Section 1 : Coding

1. Problem Statement
P3

P3

P3

P3
05

05

05

05
Imagine you are managing a circular conveyor belt in a factory. The
1A

1A

1A

1A
conveyor belt runs in a loop, and you need a program to manage the items
50

50

50

50
24

24

24

24
on it. The program should let you:
Add items to the start of the belt when they need to be processed first.Add
items to the end of the belt for less urgent tasks.Add items at a specific
position when they need to be placed in a particular order.View all items on
the belt to check the sequence.Exit the program when you're done
managing the belt.Design a menu-driven program to handle these tasks
using a circular single-linked list.

Answer
3

3
5P

5P

5P

5P

// You are using GCC


0

A0
1A

1A

1A

#include <stdio.h>
50

50

50

50
24

24

24

24
#include <stdlib.h>
3

P3

P3

P3
5P

05

05

05
struct node{
A0

1A

1A

1A
int data;
01

50

50

50
5

struct node *next;


24

24

24

24
}*head=NULL;

struct node *getnode(){


struct node *newnode;
newnode=(struct node *)malloc(sizeof(struct node));
scanf("%d",&newnode->data);
newnode->next=NULL;
return newnode;
}
struct node *insertbegin(struct node *head){
P3

P3

P3

3
5P
05

05

05
struct node *newnode,*ptr=head;

0
1A

1A

1A

1A
newnode=getnode();
50

50

50

50
if(head==NULL){
24

24

24

24
head=newnode;
newnode->next=head;
}
else{
newnode->next=head;
while(ptr->next!=head){
ptr=ptr->next;
}
ptr->next=newnode;
head=newnode;
P3

P3

P3

P3
05

05

05

05
}
1A

1A

1A

1A
printf("Node with data %d inserted at the begining.\n",newnode->data);
50

50

50

return head; 50
24

24

24

24

struct node *insertend(struct node *head){


struct node *newnode,*ptr=head;
newnode=getnode();
if(head==NULL){
head=newnode;
newnode->next=head;
}
3

3
5P

5P

5P

5P

else{
0

A0
1A

1A

1A

while(ptr->next!=head){
1
50

50

50

50
24

24

24

24
ptr=ptr->next;
3

P3

P3

P3
5P

05

05

05
}
A0

1A

1A

1A
ptr->next=newnode;
01

50

50

50
5

newnode->next=head;
24

24

24

24
}
printf("Node with data %d inserted at the end.\n",newnode->data);
return head;
}
struct node insertatpos(struct node *head){
struct node *newnode,*ptr=head;
int pos;
newnode=getnode();
scanf("%d",&pos);
if(pos==1){
P3

P3

P3

3
5P
05

05

05
head=insertbegin(head);

0
1A

1A

1A

1A
}
50

50

50

50
else{
24

24

24

24
for(int i=2;i<pos;i++){
ptr=ptr->next;
}
newnode->next=ptr->next;
ptr->next=newnode;
}
printf("Node with data %d inserted at position %d.\n",newnode->data,pos);
return head;
}
void display(struct node *head){
P3

P3

P3

P3
05

05

05

05
struct node *t=head;
1A

1A

1A

1A
if(head==NULL)
50

50

50

return; 50
24

24

24

24

while(t->next!=head){
printf("%d",t->data);
t=t->next;
}
printf("%d",t->data);
return;
}
void print(struct node *h){
t=head;
while(head && t->next!=head){
3

3
5P

5P

5P

5P

printf("%d",t->data);
0

A0
1A

1A

1A

t=t->next;
1
50

50

50

50
24

24

24

24
}
3

P3

P3

P3
5P

05

05

05
}
A0

1A

1A

1A
int main(){
01

50

50

50
5

int k;
24

24

24

24
while(1){
scanf("%d",&k);
switch(k){
case 1 :
head=insertbegin(head);
break;
case 2 :
head=insertend(head);
break;
case 3 :
P3

P3

P3

3
5P
05

05

05
head=insertatpos(head);

0
1A

1A

1A

1A
break;
50

50

50

50
case 4 :
24

24

24

24
display(head);
break;
case 5 :
exit(0);
default:
printf("Invalid choice .\n");
break;
}
}
}
P3

P3

P3

P3
05

05

05

05
1A

1A

1A

1A
50

50

50

50
24

24

24

24
3

3
5P

5P

5P

5P
0

A0
1A

1A

1A

1
50

50

50

50
24

24

24

24
Status : Wrong Marks : 0/10
3

P3

P3

P3
5P

05

05

05
A0

1A

1A

1A
01

50

50

50
5

2. Problem Statement
24

24

24

24
Raj is looking for help with a circular linked list challenge! Design a
program that creates a circular linked list, then prompts the user to enter a
new node's value and the position where it should be inserted. After
inserting the new node, display the updated circular linked list to show the
changes.

Answer
P3

P3

P3

3
#include<stdio.h>

5P
05

05

05
#include<stdlib.h>

0
1A

1A

1A

1A
50

50

50

50
struct node{
24

24

24

24
int data;
struct node *next;
}*head;

struct node *getnode(){


struct node *newnode;
newnode=(struct node *)malloc(sizeof(struct node));
scanf("%d",&newnode->data);
newnode->next=NULL;
P3

P3

P3

P3
return newnode;
05

05

05

05
}
1A

1A

1A

1A
struct node *createsll(struct node *head){
50

50

50

struct node *newnode,*ptr; 50


24

24

24

24

newnode=getnode();
if(head==NULL){
head=newnode;
newnode->next=head;
}
else{
ptr=head;
while(ptr->next!=head){
ptr=ptr->next;
3

}
5P

5P

5P

5P

ptr->next=newnode;
0

A0
1A

1A

1A

newnode->next=head;
1
50

50

50

50
24

24

24

24
}
3

P3

P3

P3
5P

05

05

05
return head;
A0

1A

1A

1A
}
01

50

50

50
5

void insertpos(struct node *head){


24

24

24

24
struct node *ptr=head,*newnode;
int pos;
newnode=getnode();
scanf("%d",&pos);
if(pos==1){
newnode->next=head;
while(ptr->next!=head){
ptr=ptr->next;
}
ptr->next=newnode;
P3

P3

P3

3
5P
05

05

05
head=newnode;

0
1A

1A

1A

1A
}
50

50

50

50
else{
24

24

24

24
for(int i=2;i<pos&&ptr!=NULL;i++){
ptr=ptr->next;
}
newnode->next=ptr->next;
ptr->next=newnode;
}
}
void display(struct node *head){
struct node *ptr=head;
while(ptr->next!=head){
P3

P3

P3

P3
05

05

05

05
printf("%d\t",ptr->data);
1A

1A

1A

1A
ptr=ptr->next;
50

50

50

} 50
24

24

24

24

printf("%d\t",ptr->data);
}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
head=createsll(head);
}
insertpos(head);
display(head);
3

3
5P

5P

5P

5P

}
0

A0
1A

1A

1A

1
50

50

50

50
24

24

24

24
24 24 24 24
50 50 50 5 01
1A 1A 1A
0 5P 05 05 A0
5P
3 P3 P3 3

24 24 24 Status : Correct 24
50 50 50 50
1A 1A 1A 1A
0 5P 05 05 05
3 P3 P3 P3

24 24 24 24
50 50 50 50
1A 1A 1A 1A
0 5P 05 05 05
3 P3 P3 P3

24 24 24 24
50 50 50 50
1
Marks : 10/10

A0 1A 1A 1A
5P 05 0 5P 05
3 P3 3 P3

You might also like