Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume that the following types and variables have been defined in C and are avail- able for use: type def char Airport Code[4] type def

Assume that the following types and variables have been defined in C and are avail- able for use: type def char Airport Code[4] type def struct Node Tag { Airport Code Airport; struct NodeTag *Link; } Node Type; Node Type *L, *M, *N; Write a function, Insert New First Node(A,&L), which inserts a node having the air- port code A as the new first node of list, L, where &L is the address of variable L. Write a function, Delete First(&L), which deletes the first node of a linked list L. Given a non-null pointer N to a node of a list L, and a pointer M to a new node to be inserted, write a C function to insert the node that is Ms referent before the node that is Ns referent on list L. (Hint: Adjust pointers to insert M after N and then swap the airport codes in N and M.] Write a function, Copy(L), which makes a copy of a linked list, L, and returns a pointer to the first node of the copy. Write a function, Reverse(&L), which reverses the order of the nodes on list L. For example, if L == (ZRH, GLA, YYZ) beforehand, then executing Reverse(&L) changes L to be the list L == (YYZ, GLA, ZRH). (Hint: Write two subroutines to remove the first node N of a list L1, and to insert a node N as the new first node on a list L2. Then, starting with an empty list L2 = NULL, successively remove nodes from L1 and insert them on L2 until L1 is empty.) (Note: The airport codes: ZRH, GLA, and YYZ stand for Zrich, Switzerland; Glasgow, Scotland; and Toronto, Ontario, respectively.) What is wrong with the following search program for finding the node on list L containing the airport code A and returning a pointer to it? 1 Node Type *FindNode(char *A, Node Type *L) 1 { 1 1 while ( (strcmp(L->Airport, A) != 0) && (L != NULL)) { 5 l L = L->Link; | } 1 return L; } How could you fix the bug in the program above by changing only one line? == Given two lists L1 and L2, write a function, Concat(L1,L2), to return a pointer to a list in which the nodes of L2 follow the nodes of L1. For example, if, beforehand, 11 (ARN, BRU) and L2 == (JFK, SAN, HKG), then the node pointer returned by Concat(L1,L2) should point to the list (ARN, BRU, JFK, SAN, HKG). (Note: ARN is Stockholm, Sweden, and HKG is Hong Kong.) What is wrong with the following algorithm for finding the last node of a list Land returning a pointer to it? 1 Node Type *LastNode(Node Type *L) { if (L != NULL) { do L = L->Link; while (L->Link != NULL); } 5 return L; 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Were multiple treatments used? Did they interfere with each other?

Answered: 1 week ago