Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 100 Lab Eight Fall 2018 Create a directory called lab8 on your machine using mkdir lab8. Complete the following two programs. 1. Name this

CS 100 Lab Eight Fall 2018

Create a directory called lab8 on your machine using mkdir lab8. Complete the following two programs.

1. Name this program one.c You can download the starting one.c from Blackboard. The starting one.c

creates a linked list of 13 nodes to represent ELEVENPLUSTWO. Your job is to relink the 13 nodes in the

specified space to form a linked list to represent "TWELVEPLUSONE". You can only change the next field

of these 13 nodes. You cant change the info field of any nodes.

one.c is below

#include  typedef struct _letter { char info; struct _letter *next; } Letter; int main(void) { Letter a, b, c, d, e, f, g, h, i, j, k, l, m; a.info = 'E'; b.info = 'L'; c.info = 'E'; d.info = 'V'; e.info = 'E'; f.info = 'N'; g.info = 'P'; h.info = 'L'; i.info = 'U'; j.info = 'S'; k.info = 'T'; l.info = 'W'; m.info = 'O'; a.next = &b; b.next = &c; c.next = &d; d.next = &e; e.next = &f; f.next = &g; g.next = &h; h.next = &i; i.next = &j; j.next = &k; k.next = &l; l.next = &m; m.next = NULL; // Print the word Letter *ptr = &a; while ( ptr != NULL ) { printf("%c", ptr->info); ptr = ptr->next; } printf(" "); // Relinks the 13 nodes here so that it spells "TWELVEPLUSONE" // YOU CANNOT CHANGE THE "info" FIELD of ANY NODES // After rearranging, print the new word ptr = &k; while ( ptr != NULL ) { printf("%c", ptr->info); ptr = ptr->next; } printf(" "); return 0; }

2. Name this program two.c You can download two.c as shown below from Blackboard. This program will

first read in a word, then build a linked list to represent the word, and finally print out the linked list in the

format as specified.

two.c below

#include

#include

typedef struct _letter {

char info;

struct _letter *next;

} Letter;

// Build a linked list to represent the specified word.

// Return the head of the linked list built.

Letter *buildList(char word[]);

// Print the linked list.

// For example, if the linked list represents CRIMSON,

// it prints C-->R-->I-->M-->S-->O-->N

void printList(Letter *head);

int main()

{

char word[100];

printf("Enter a word: ");

scanf("%s", word);

Letter *head=buildList(word);

printList(head);

return 0;

}

Your job is to complete the two functions as specified below.

Letter *buildList(char word[]); Build a linked list to represent the specified word and

return the head of the linked list built.

void printList(Letter *head); Print the linked list. For example, if the linked list

represents CRIMSON, it will print C-->R-->I-->M-->S-->O-->N

Submit your lab

First, on your machine, compress your lab8 directory into a single (compressed) file, i.e. lab8.zip.

Please make sure lab8.zip contains the lab8 directory as well as one.c and two.c under it.

Second, once you have a compressed file named lab8.zip, submit that file to Blackboard.

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

Strong analytical, communication, and problem-solving skills

Answered: 1 week ago