0% found this document useful (0 votes)
3 views3 pages

SLL Assignment

The document outlines three programming tasks involving linked lists. The first task involves managing a singly linked list by inserting elements based on user input, while the second task focuses on updating a guest list by removing specific guests. The third task requires converting a list of binary digits stored in a linked list into its decimal equivalent, with specific input and output formats provided for each task.

Uploaded by

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

SLL Assignment

The document outlines three programming tasks involving linked lists. The first task involves managing a singly linked list by inserting elements based on user input, while the second task focuses on updating a guest list by removing specific guests. The third task requires converting a list of binary digits stored in a linked list into its decimal equivalent, with specific input and output formats provided for each task.

Uploaded by

deepa kanmani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. Ram wants to create a program to manage a singly linked list.

He wants to insert
elements at the beginning of the list based on user input, insert a new element after the
first element of the list and finally display the entire list after performing the insertion
operations.

Can you assist Ram in completing this?


Input format :
The first line of input contains an integer n, denoting the number of elements in the linked list.
The second line contains n integers, representing the elements.
The third line contains an integer m, representing the new element to be inserted.
Output format :
The output prints the updated list, after performing the insertion operations.

Sample test cases :


Input 1 :
3
15 36 49
27
Output 1 :
49 27 36 15

2.
Sophie is managing a guest list for an upcoming event. Each guest is represented by an integer
ID. Due to some changes, Sophie needs to update the guest list by removing the first guest,
another guest from the end of the list, and a third guest from a specific position within the list.

Your task is to help Sophie implement a function to perform these deletions and manage the
guest list efficiently.
Input format :
The first line of input contains an integer G, the number of guests currently in the list.
The second line contains G integers, each representing the ID of a guest.
The third line contains an integer p, the position (0-based index) of the guest to be removed.
Output format :
The first line of output prints the linked list after deleting the first node.
The second line of output prints the linked list after deleting the last node.
The third line of output prints the linked list after deleting the node at the specified position.

Sample test cases :


Input 1 :
5
10 20 30 40 50
2
Output 1 :
20 30 40 50
20 30 40
20 30
Input 2 :
5
11 22 33 44 55
0
Output 2 :
22 33 44 55
22 33 44
33 44

[Link] is studying data structures and algorithms and wants to implement a simple program to
work with linked lists. She has a list of binary digits, and she needs to convert them into a
decimal number.

She's looking for your help to write a program that takes in a list of binary digits, stores them in a
linked list, and then calculates the decimal value of the binary number. Can you assist her in
achieving this?

Example

Input:
4
0011
Output:
3
Explanation:
For the first binary digit (0), dec remains 0.
For the second binary digit (0), dec remains 0.
For the third binary digit (1), dec becomes 1 (0 * 2 + 1).
For the fourth binary digit (1), dec becomes 3 (1 * 2 + 1).
Input format :
The first line contains an integer n, representing the number of binary digits Priya has.
The second line contains n space-separated integers, each being either 0 or 1, representing the
binary digits.
Output format :
The output displays the decimal equivalent of the binary number formed by the linked list.
If n is 0, the output prints "List is empty".

Refer to the sample output for the formatting specifications.


Code constraints :
0 < n < 25
Each node will be either 0 or 1
Sample test cases :
Input 1 :
4
0 0 1 1
Output 1 :
3
Input 2 :
7
1 1 0 0 0 0 1
Output 2 :
97
Input 3 :
0
Output 3 :
List is empty

You might also like