Question

C Program: How do I create two linked lists of characters from user input and concatenate...

C Program: How do I create two linked lists of characters from user input and concatenate the two linked lists?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include <stdio.h>
#include <stdlib.h>

struct node
{
int data;
struct node *next;
};

void display(struct node *head)
{
if(head == NULL)
{
printf("NULL\n");
}
else
{
printf("%d ", head -> data);
display(head->next);
}
}

void concatenate(struct node *a,struct node *b)
{
if( a != NULL && b!= NULL )
{
if (a->next == NULL)
a->next = b;
else
concatenate(a->next,b);
}
else
{
printf("Either a or b is NULL\n");
}
}

int main()
{
struct node *prev,*a, *b, *p;
int n,i;
printf ("number of elements in a:");
scanf("%d",&n);
a=NULL;
printf("Enter elements in a: ");
for(i=0;i<n;i++)
{
p=malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
if(a==NULL)
a=p;
else
prev->next=p;
prev=p;
}
printf ("number of elements in b:");
scanf("%d",&n);

printf("Enter elements in b: ");
b=NULL;
for(i=0;i<n;i++)
{
p=malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
if(b==NULL)
b=p;
else
prev->next=p;
prev=p;
}
concatenate(a,b);
display(a);
return 0;
}

ㅃ main.c-Code:Blocks 13.12 Eile Edit iew Search Project Build Debug Fortran woSmith Tools ToolsPlugins DoxyBlocks Settings He​​​​​​​

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
C Program: How do I create two linked lists of characters from user input and concatenate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java, How would I create a program that does this from user input? studentld: consists...

    In Java, How would I create a program that does this from user input? studentld: consists of the first two characters of the student's first name, student's birth year, and the last two characters of the last name. For instance, if the student's full name is John mith and birthyear is 1988, then the studentid will be jo1988th. s email: consists of the first name, dot, last name, and @pa2.com. For instance, if the student's full name is John Smith,...

  • Need Java help: 1. Create a Java program that accepts input String input from a user...

    Need Java help: 1. Create a Java program that accepts input String input from a user of first name. 2. Create a Java program that accepts input String input from a user of last name. 3. Concatenate the Strings in a full name variable and print to the console.

  • Create a program that takes in user input and stores the input into an array. Also...

    Create a program that takes in user input and stores the input into an array. Also within the program show how you can: show the elements in the array, remove an element from the array, add an element to the array. Do NOT ask the user how many elements they want to add, instead once they are done adding, they should hit ‘q’ and it should break out of the input. This is a c++ program. The input type shall...

  • Create a program in C++ that has only an integer type input called in. This program...

    Create a program in C++ that has only an integer type input called in. This program interchanges two characters’ positions based on user’s input value. The specifications are: If user enters 0, first and second characters are swapped. If user enters 1, first and last characters are swapped. If users enter 2, second and last characters are swapped. For example: The original text is “ABC”. First letter is A, second letter is B and last letter is C. If 0...

  • please use pythom Write a program that ask the user for a string as input. It...

    please use pythom Write a program that ask the user for a string as input. It should duplicate of all the characters in the string and print it back out to the user. For example: AbC123 would be printed out as AAbbCC112233 Write a program that takes two lists and displays the items that occur in both lists. For example: ["a", "b", "c"] ["c", "a", "d"] would display a and c

  • Assembly program: NASM assembler write a program to print the location of character "i" from a input string from left to right. User inputs a strings upto 40 characters.

    Assembly program: NASM assembler write a program to print the location of character "i" from a input string from left to right. User inputs a strings upto 40 characters.

  • ​c++ program that takes user input from the console and store the data into a linked list.

    c++ program that takes user input from the console and store the data into a linked list. The input made of 4 objects associated to a car: model, make, mileage and year. My program should take the how many inputs the user want to make, followed by the inputs themselves. After the input, my program should print the data inside the linked list. So far, the issue is that my program print some of the input, but not all. Input sample:3HondaSentra89002017ToyotaCamri1098271999NissanSentra87261987current...

  • in java please Create an array of characters. Ask the user to enter two characters. Tell...

    in java please Create an array of characters. Ask the user to enter two characters. Tell the user which character occurs more frequently For example, suppose the array contains (a, b, c, d, 8, 2, e, e, f, g and the user enterse and then the program will say that occurs more frequently thanL Bonus: Display a list of all characters in the array with their frequencies. Each value should appear only once For example for the array(a, b, c,...

  • Pig Latin program using Linked Lists C++

    Write a program that prompts the user to input a string and then outputs the string in the pig Latin form. The rules for converting a string into pig Latin form are asfollows:a. If the string begins with a vowel, add the string "-way" at the end of the string. for example, the pig Latin form of the string "eye" is "eye-way".b. If the string does not begin with a vowel, first ass "-" at the end of the string....

  • Create a Python Program that will ask the user for a password (use input) Verify that...

    Create a Python Program that will ask the user for a password (use input) Verify that the password meets the following conditions: -must be 12 characters long -must have uppercase and lowercase -must contain at least 1 special character (!~#$%^&*{}+_) -must be a mix of numbers and letters You must do this only using regular expressions so for instance this will not be accepted if len(password) <12: At the end of the program tell the user their password is ok...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT