logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

Create a Sorted List abstract data type and Functions to be implemented

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Advanced Linked Lists

typedef structNODE{

value_tvalue;

key_tkey;

struct NODE* next;

struct NODE* sort;

} Node;

In this linked list:

  • The datatype for the value being stored is called value_t
  • The datatype for the key being stored is called key_t
  • As in lab 4, nextlinks to the node in the order it was added to the list (either at the head or the tail)oThis will be referred to as insertionorder
  • Similar tolab 4, sortlinks to the node where the key is greater or equal to its key
  • e. the list is kept in ascending order by key
  • This will be referred to as key sortorder
  • Note: unlike lab 4, there is only one key

Create a Sorted List abstract data type

  • Has two heads (headfor insertionorder, head_sortfor key sort order)
  • Has twotails (tailfor insertionorder, tail_sortfor key sort order)
  • If you are notusingthe bonus Node struct
  • Has two “previous tail” (the node pointing to the tail node) links prev_tailand prev_tail_sorted
  • Has anintfield called size that stored the node count (the number of elements in the list)The datatype should be called Sorted_List

Functions To be implemented

All functions, except where noted,return SUCCESS if the function can complete or FAIL if not

  • int size (Sorted_List *)
  • int push(Sorted_List *,value_t , key_t)oadd the node to the headof the list

 the node must also be inserted in ascendingsortorderby key, using the sort link

  • int append(Sorted_List *, value_t , key_t)osimilar to push, except the node gets added to tail
  • int remove_first(Sorted_List * , value_t * , key_t *)oremoves the node from the head of the list

O returns the value and key of the removed node (and frees the node)

o remember to update the sort order links if not using doubly linked lists, you will need to find the previous sorted nodeto change its sort order link

  • int remove_last(Sorted_List * , value_t * , key_t * )osimilar to remove_first, except it removes the node from the tail •int remove_smallest_key(Sorted_List * , value_t * ,key_t * )

removes the node with the smallest key

o returns the value and key of the removed node (and frees the node)

o remember to update the insertionorder links if not using doubly linked lists, you will need to find the previous insert order node to change its insertionorder link

  • int remove_largest_key (Sorted_List * , value_t * , key_t * )

osimilar to remove_smallest_key, except it removes the node with the largest key

  • void empty_list(Sorted_List *)

O empties the contents of the list

  • void destroy_list(Sorted_List *)oempties the contents ofthelist,as well as freeing the list itself

To testthe Sorted List ADT

Write two programs called a4q1a_char.c and  a4q1a_int.c

  • Data types used

a4q1a_int.c

has its value_tdatatype set equal to int

has it key_tdatatype set equal to double

a4q1a_char.c

hasitsvalue_t datatype set equal to char[80]

  • i.e. it can take strings up to 79 characters in length

has its key_tdatatype setequaltoint

  • its value is set equal to the length of the string
  • Both programs readina text file that contains a series of commands, one per line (i.e each ending with a newline)

The name of the text file should be entered as a command line argument§If there is no file name, read from stdin

  • this can use IO redirect, i.e.a4q1a_int < filename.txt
  • If using keyboard input, exit using ^d•All commands are echoed to stdout, followed by a colon :,

After that the results of the command follows,

  • usually on the same line following11–strlen(cmd name)spaces oron the next linewhen notedNote: Silent commands do not have the colon : after the command, but rather after the command name
  • Remember to free the sorted list at the end of the program (use destroy_list)General Note:The two programs should be almost identical, with the following differences

The file input will be slightlydifferent depending on the data type and nature of the input data

Your will have to write similar, but not identicalvoid print_list_all(Sorted_List * )andvoid print_list_sort(Sorted_List * )functions

These functionsprint out the lists according totheir respectivesort orders

See the report commands section below for details(the print_alland print_sortcommands)

You will have to have your make file recompile allfiles that mention or usevalue_t and key_tvariables or Sort_List structs when compiling the two programs

To do this you will need to use condition compilation (see Week1 lecture notes)§In specific, use #ifdef CHAR to compile using the char[80] typedef definitionof value_t and #ifdef INT to compile using the int typedef definition of value_t

E.g.if you stored all your Sort_List ADT functions in a single file called sort_list.cThenfor a4q1a_char.cyou could havein your make fileacommandlikegcc -Wall -ansi -DCHAR-csort_list.c

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

890 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

762 Answers

Hire Me
expert
Husnain SaeedComputer science

978 Answers

Hire Me
expert
Atharva PatilComputer science

737 Answers

Hire Me
August
January
February
March
April
May
June
July
August
September
October
November
December
2025
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
SunMonTueWedThuFriSat
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30