Assignment 3 – Linked Lists and Multiple Sources solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

Problem 3.1 A linked list of characters (1 point) Presence assignment, due by 18:30 h today Using the example from the slides (Lecture 3 & 4, pages 22 − 25), write a program that uses a linked list. Your program should wait for input from the keyboard. Entering from the keyboard a ’1’ will just add the following character (read as next from the keyboard) to the end of the list, while a ’2’ inserts at the beginning of the list. Entering a ’3’ will remove the first element from thelist, a’4’willprintthelistwhilea’5’willemptythelistandfreethememoryusedbythelist and quit the execution of the program. Use a switch-case statement to decide which action to take. You can assume that the input will be valid. Testcase 3.1: input 2 a 2 c 1 b 4 3 4 5 Testcase 3.1: output c a b a b
Problem 3.2 An enhanced linked list of characters (2 points) Extend your program for Problem 3.1 by writing a function for inserting a new element into the list at a given position and a function for reversing the order of the elements in the list. Your program should wait for input from the keyboard. A ’6’ followed by a number and a character (the position and the element to be inserted) should insert the character at the position of the number (the first element in the list has position 0). You can assume that the input does not containanylogicalerrors(e.g.,’6’isalwaysfollowedbyapositionandacharacter,and’2’and’1’ arefollowedbyonecharacter). However,ifthepositionforinsertingisnegativeorisgreaterthan thenumberofelementsinthelistthenprintonthestandardoutput“Invalid position!”. A ’7’ should reverse the order of the characters in the list without allocating new nodes or using a doubly linked list (i.e., only with the use of pointers). Use a switch-case statement to decide which action to take.
Testcase 3.2: input 2 a 2 c 1 b 4 3 4 6 1 x 4 6 11 b 7 4 5
Testcase 3.2: output c a b a b a x b Invalid position! b x a
Problem 3.3 A doubly linked list of numbers (4 points) Createadatatypethatimplementsadoublylinkedlistofintegernumbers. Writeaprogramthat tests your doubly linked list with the testcase given below. Entering from the keyboard an ’a’ will just add the following number (also entered from the keyboard) to the list at the beginning, while an ’r’ will remove all elements with the given number from the list, a ’p’ will print the currentlist,whilea’b’willprinttheelementsoflistbackwards. A’q’willemptythelist,freethe memory used by the doubly linked list and quit the execution of the program. Youcanassumethattheinputdoesnotcontainlogicalerrors(i.e.,ifthecommandis’r’,youcan assumethatanumberwillfollow). However,anumbertobedeletedmaynotbecurrentlyinthe list. In this case, the message “The element is not in the list!” should be printed on the standard output. Use a switch-case statement to decide which action to take. Testcase 3.3: input a 7 a 2 a 5 p a 2 a 11 a 7 a 11 p r 11 p b r 18 q Testcase 3.3: output 5 2 7 11 7 11 2 5 2 7 7 2 5 2 7 7 2 5 2 7 The element is not in the list!
Problem 3.4 Multiple sources (1 point) Modify your solution for Problem 3.1 such that you separate your source code into three files: struct declaration and function declarations in linked_list.h, function definitions in linked_list.c, and your main function in use_linked_list.c. You can assume that the input will be valid. Testcase 3.4: input 2 a 2 c 1 b 4 3 4 5 Testcase 3.4: output c a b a b
How to submit your solutions • Your source code should be properly indented and compile with gcc without any warnings (You canuse gcc -Wall -o program program.c). Insertsuitablecomments(notoneveryline…) to explain what your program does. • Please name the programs according to the suggested filenames (they should match the description of the problem) in Grader. Otherwise you might have problems with the inclusion of header files. Each program must include a comment on the top like the following: /* JTSK-320112 a3 p1.c Firstname Lastname myemail@jacobs-university.de */
• You have to submit your solutions via Grader at https://cantaloupe.eecs.jacobs-university.de. If there are problems (but only then) you can submit the programs by sending mail to k.lipskoch@jacobs-university.de with a subject line that begins with JTSK-320112. It is important that you do begin your subject with the coursenumber, otherwise I might have problems to identify your submission. • Pleasenote,thatafterthedeadlineitwillnotbepossibletosubmitanysolutions. Itisuselesstosend late solutions by mail, because they will not be accepted. This assignment is due by Tuesday, February 20th, 10:00 h