Write a program to add data anywhere of the LinkedList. Use switch case to do the program. If possible, use while (1) to continue the loop. So, the user can continue to insert data as well as show data without quilting from the program. The user will get the following options to choose from.1.Insert data at the beginning 2.Insert data in the middle 3. Insert data at the end 4. Show data 5.Quit
It's a C program. And how to show data?
Hi i have solved your problem hope this will be helpful to you kindly give a thumbs up if you like it and if you have any doubt regarding the code please do comment.
code:-
#include<stdio.h>
#include<conio.h>
struct node
{
int data;
struct node *next;
}*start=NULL,*q,*t;
int main()
{
int Choice;
void Insert_Begning();
void Insert_End();
int Insert_Position();
void Display_List();
void Delete_Begning();
void Delete_End();
int Delete_Position();
while(1)
{
printf("\n\n---- Singly Linked List ---- \n\n");
printf("\n1.Insert into List \n2.Display the List \n3.Delete From
List \n4.Exit from the Program \n\n");
printf("Enter your choice between (1-4):");
scanf("%d",&Choice);
switch(Choice)
{
case 1:
printf("\n---- Please Select the Proper option ----");
printf("\n1.Insert at beginning\n2.Insert at end\n3.Insert at
specified position\n4.Exit");
printf("\n\nEnter your choice(1-4):");
scanf("%d",&Choice);
switch(Choice)
{
case 1: Insert_Begning();
break;
case 2: Insert_End();
break;
case 3: Insert_Position();
break;
case 4: exit(0);
default: printf("Wrong Choice!!");
}
break;
case 2: Display_List();
break;
case 3: printf("\n---- Delete Menu ----");
printf("\n1.Delete from beginning\n2.Delete from end\n3.Delete from
specified position\n4.Exit");
printf("\n\nEnter your choice(1-4):");
scanf("%d",&Choice);
switch(Choice)
{
case 1: Delete_Begning();
break;
case 2: Delete_End();
break;
case 3: Delete_Position();
break;
case 4: exit(0);
default: printf("Wrong Choice!!");
}
break;
case 4: exit(0);
default: printf("Wrong Choice!!");
}
}
return 0;
}
void Insert_Begning() //Function to insert at Begning
{
int Number;
t=(struct node*)malloc(sizeof(struct node));
printf("Enter data:");
scanf("%d",&Number);
t->data=Number;
if(start==NULL) //Check if the list is empty
{
t->next=NULL;
start=t;
}
else
{
t->next=start;
start=t;
}
}
void Insert_End() //Function to insert at End
{
int Number;
t=(struct node*)malloc(sizeof(struct node));
printf("Enter data:");
scanf("%d",&Number);
t->data=Number;
t->next=NULL;
if(start==NULL) //Check If the list is empty
{
start=t;
}
else
{
q=start;
while(q->next!=NULL)
q=q->next;
q->next=t;
}
}
int Insert_Position() //Function to insert at specified
position
{
int pos,i,Number;
if(start==NULL)
{
printf("List has no element !!");
return 0;
}
t=(struct node*)malloc(sizeof(struct node));
printf("Enter data:");
scanf("%d",&Number);
printf("Enter position to insert:");
scanf("%d",&pos);
t->data=Number;
q=start;
for(i=1;i<pos-1;i++)
{
if(q->next==NULL)
{
printf("There are less elements!!");
return 0;
}
q=q->next;
}
t->next=q->next;
q->next=t;
return 0;
}
void Display_List() //Function to Display the list
{
if(start==NULL)
{
printf("List has no element !!");
}
else
{
q=start;
printf("The linked list is:\n");
while(q!=NULL)
{
printf("%d->",q->data);
q=q->next;
}
}
}
void Delete_Begning() //Function to delete from Begning
{
if(start==NULL)
{
printf("The list is empty!!");
}
else
{
q=start;
start=start->next;
printf("Deleted element is %d",q->data);
free(q);
}
}
void Delete_End() //Function to delete from End
{
if(start==NULL)
{
printf("The list is empty!!");
}
else
{
q=start;
while(q->next->next!=NULL)
q=q->next;
t=q->next;
q->next=NULL;
printf("Deleted element is %d",t->data);
free(t);
}
}
int Delete_Position() //Function to delete from Specified
Position
{
int pos,i;
if(start==NULL)
{
printf("List is empty!!");
return 0;
}
printf("Enter position to delete:");
scanf("%d",&pos);
q=start;
for(i=1;i<pos-1;i++)
{
if(q->next==NULL)
{
printf("There are less elements!!");
return 0;
}
q=q->next;
}
t=q->next;
q->next=t->next;
printf("Deleted element is %d",t->data);
free(t);
return 0;
}
output:-




Happy to help :)
Write a program to add data anywhere of the LinkedList. Use switch case to do the...
// Group Names: // Date: // Program Description: // Import required packages //--> // Declare class (SwitchDoLab) //--> { // Declare the main method //--> { // Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3. //--> //--> //--> // Create an integer variable named choice to store user's option. //--> // Create a Scanner object // Create...
Instructions We're going to create a program which will allow the user to add values to a list, print the values, and print the sum of all the values. Part of this program will be a simple user interface. 1. In the Program class, add a static list of doubles: private statie List<double> _values new List<double>) this is the list of doubles well be working with in the program. 2. Add ReadInteger (string prompt) , and ReadDouble(string prompt) to the...
Write a perl program Use a while loop to get user input until the user enters "quit" Use a regex to replace any occurrence of the word "python" with the word "perl" and print out the updated version Provide the perl program (.pl file) as well as a screenshot of the output (show at least one example with python being replaced)
Write codes that will produce the screen as shown Firstly, the program prompts user to enter his name. Then it will display Hello <user name>. Next it prints out a menu which contains 5 options (1- add two integers, 2- add two strings, 3- compute factorial, 4- reverse a string, 5- quit program). Code all 5 tasks appropriately. When the task is completed (not including quitting program of course), the menu pops up again and asks user to try...
How would this switch statement be modified to not use "continue"? This piece of code is part of a larger assignment and that assignment prohibits the use of "continue" for switch statements. How do I modify this code so that it still does what I want it to do, without using "continue"? while (true) { choice = displayMenu(keyboard); switch (choice) { case 'D': case 'd': { courseStudents.displayStudentList(); continue; } case 'A': case 'a': { int id; double stGpa; System.out.println("Enter...
Write a Program that has a menu with a layout below, that asks the user if they want to: 1. Converts from feet and inches to meter and centimeters 2. Converts from meter and centimeters to feet and inches 3. Quit the program The program should continue as long as the user asks it to. The program will use a switch statement for the menu option selection. Either a do loo or a do-while loop can be used for the overall...
Write a C++ program that prompts the user to enter two numbers. Then prompt the user to select from the following options: a. Add the numbers. b. Multiply the numbers. c. Terminate the program Use the appropriate control structures (loops, if else, switch-case, etc) to make your program as short and efficient as possible. Minor syntax errors are forgiven in this exercise; just focus on the correct structure, declarations and sequence of instructions
Write a complete C++ program that will: Declare a vector of integers Use a pointer to dynamically allocate an array of 10 elements Ask the user how many values they would like to have in the data structures Read in the user’s response and make sure that it is greater than 20 (error loop) Generate the number of integers that the user asked for and store them into both data structures. The integer values should be unique unordered values (no...
Lab 7 Add three instance variables to your class RightTriangle from lab 5. The first two are of type int and are called xLoc and yLoc and the third is of type int called ID. Also add a static variable of type double called scaleFactor. This should be initialized to a default value of 1. Update the constructor to set the three new instance variables and add appropriate get and set methods for the four new variables. All set methods...
need help!! c++
HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...