
Program plan:
- Item, start variablesare used for input. There is structure listnode having data, nextPtr member variables which represents the linked list node.
- void insert(node **head, int value) function inserts the node in the a linked list.
- node *concat(node *flist, node *slist) function concat the two linked list and return the resultant linked list.
- void printList(node *head) function display the contents of the linked list.
Program description:
The main purpose of the program is to perform the concatenation of two linked list by implanting the concept which is same as strcat() function of string.

Explanation of Solution
Program:
#include <stdio.h> #include <conio.h> #include <alloc.h> #include <ctype.h> //structure of node of the linked list typedefstruct listnode { int data; struct listnode *nextPtr; } node; //function to insert a node in a linked list void insert(node &head,int value); //recursive function to concate the linked list node *concat(node *flist, node *slist); //function to print the content of linked list void printList(node *head); //main starts here void main() { int item; node *flist,*slist; clrscr(); //initialization of start node of linked list flist =NULL; slist =NULL; //loop to getting input from the user for first linked list while(1) { printf("\nEnter value to insert in a First List: 0 to End "); scanf("%d",&item); //check condition to terminate while loop if(item ==0) break; //insert value in a linked list insert(&flist, item); } //loop to getting input from the user for second linked list while(1) { printf("\nEnter value to insert in a Second List: 0 to End "); scanf("%d",&item); //check condition to terminate while loop if(item ==0) break; //insert value in a linked list insert(&slist, item); } // print the contents of linked list printf("\n Content of First List are as follows : "); printList(flist); // print the contents of linked list printf("\n Content of Second List are as follows : "); printList(slist); //call the function to reverse the linked list // and store the address of first node flist = concat(flist, slist); //print the contents of concated list printf("\n Concatenated List contents are as follows : "); printList(flist); getch(); } //function definition to insert node in a linked list void insert(node &head,int value) { node *ptr,*tempnode; //memory allocation for the new node ptr = malloc(sizeof(node)); //copy the value to the new node ptr->data = value; //set node's pointer to NULL ptr->nextPtr =NULL; //if the list is empty if(*head ==NULL) //make the first node *head = ptr; else { //copy the address of first node tempnode =*head; //traverse the list using loop until it reaches //to the last node while(tempnode->nextPtr !=NULL) tempnode = tempnode->nextPtr; //make the new node as last node tempnode->nextPtr = ptr; } } //function defintion to concat the list node *concat(node *flist, node *slist) { node *ptr; //check if list is empty if(flist ==NULL|| slist ==NULL) { printf("\none of the lists is empty"); //return the node returnNULL; } else { //store first node address ptr = flist; //traverse list until last node is not encountered while(ptr->nextPtr !=NULL) ptr = ptr->nextPtr; //store the address of first node of second list ptr->nextPtr = slist; } //return new list return flist; } //function definition to display linked list contents void printList(node *head) { node *ptr; //stores the address of first node ptr = head; //traverse the list until it reaches to the NULL while(ptr !=NULL) { //print the content of current node printf("%d ", ptr->data); //goto the next node ptr = ptr->nextPtr; } }
Explanation:In the above code, a structure is created which represents the node of the linked list. Two starting nodes are initialized which contains the address of first node of each list. User is asked to enter the values for first linked list and linked list is created using insert() function by passing the starting pointer and value. This process is repeated to create the second linked list. printList() function is used to display the contents of both lists. Both lists are concatenated using the concat() function by passing the both list. In this function first list is traversed up to last node and then last node pointer points to the first node of second list. Starting node address is returned and stored in the pointer. Finally, concatenated list is displayed using printList() function.
Sample output:
Want to see more full solutions like this?
Chapter 12 Solutions
C How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
- What is a functional decomposition diagram? what is a good example of a high level task being broken down into tasks in at least two lower levels (three levels in all).arrow_forwardWhat are the advantages to using a Sytems Analysis and Design model like the SDLC vs. other approaches?arrow_forward3. Problem Description: Define the Circle2D class that contains: Two double data fields named x and y that specify the center of the circle with get methods. • A data field radius with a get method. • A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius. • A constructor that creates a circle with the specified x, y, and radius. • A method getArea() that returns the area of the circle. • A method getPerimeter() that returns the perimeter of the circle. • • • A method contains(double x, double y) that returns true if the specified point (x, y) is inside this circle. See Figure (a). A method contains(Circle2D circle) that returns true if the specified circle is inside this circle. See Figure (b). A method overlaps (Circle2D circle) that returns true if the specified circle overlaps with this circle. See the figure below. р O со (a) (b) (c)< Figure (a) A point is inside the circle. (b) A circle is inside another circle. (c) A circle overlaps another…arrow_forward
- 1. Explain in detail with examples each of the following fundamental security design principles: economy of mechanism, fail-safe default, complete mediation, open design, separation of privilege, least privilege, least common mechanism, psychological acceptability, isolation, encapsulation, modularity, layering, and least astonishment.arrow_forwardSecurity in general means the protection of an asset. In the context of computer and network security, explore and explain what assets must be protected within an online university. What the threats are to the security of these assets, and what countermeasures are available to mitigate and protect the organization from such threats. For each of the assets you identify, assign an impact level (low, moderate, or high) for the loss of confidentiality, availability, and integrity. Justify your answers.arrow_forwardPlease include comments and docs comments on the program. The two other classes are Attraction and Entertainment.arrow_forward
- Object-Oriented Programming In this separate files. ent, you'll need to build and run a small Zoo in Lennoxville. All classes must be created in Animal (5) First, start by building a class that describes an Animal at a Zoo. It should have one private instance variable for the name of the animal, and one for its hunger status (fed or hungry). Add methods for setting and getting the hunger satus variable, along with a getter for the name. Consider how these should be named for code clarity. For instance, using a method called hungry () to make the animal hungry could be used as a setter for the hunger field. The same logic could be applied to when it's being fed: public void feed () { this.fed = true; Furthermore, the getter for the fed variable could be named is Fed as it is more descriptive about what it answers when compared to get Fed. Keep this technique in mind for future class designs. Zoo (10) Now we have the animals designed and ready for building a little Zoo! Build a class…arrow_forward1.[30 pts] Answer the following questions: a. [10 pts] Write a Boolean equation in sum-of-products canonical form for the truth table shown below: A B C Y 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 a. [10 pts] Minimize the Boolean equation you obtained in (a). b. [10 pts] Implement, using Logisim, the simplified logic circuit. Include an image of the circuit in your report. 2. [20 pts] Student A B will enjoy his picnic on sunny days that have no ants. He will also enjoy his picnic any day he sees a hummingbird, as well as on days where there are ants and ladybugs. a. Write a Boolean equation for his enjoyment (E) in terms of sun (S), ants (A), hummingbirds (H), and ladybugs (L). b. Implement in Logisim, the logic circuit of E function. Use the Circuit Analysis tool in Logisim to view the expression, include an image of the expression generated by Logisim in your report. 3.[20 pts] Find the minimum equivalent circuit for the one shown below (show your work): DAB C…arrow_forwardWhen using functions in python, it allows us tto create procedural abstractioons in our programs. What are 5 major benefits of using a procedural abstraction in python?arrow_forward
- Find the error, assume data is a string and all variables have been declared. for ch in data: if ch.isupper: num_upper = num_upper + 1 if ch.islower: num_lower = num_lower + 1 if ch.isdigit: num_digits = num_digits + 1 if ch.isspace: num_space = num_space + 1arrow_forwardFind the Error: date_string = input('Enter a date in the format mm/dd/yyyy: ') date_list = date_string.split('-') month_num = int(date_list[0]) day = date_list[1] year = date_list[2] month_name = month_list[month_num - 1] long_date = month_name + ' ' + day + ', ' + year print(long_date)arrow_forwardFind the Error: full_name = input ('Enter your full name: ') name = split(full_name) for string in name: print(string[0].upper(), sep='', end='') print('.', sep=' ', end='')arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning



