CS计算机代考程序代写 CALIFORNIA STATE POLYTECHNIC UNIVERSITY

CALIFORNIA STATE POLYTECHNIC UNIVERSITY

11CALIFORNIA STATE POLYTECHNIC UNIVERSITY
Computer Science Department
CS 2640 02 (3) T. Nguyen/F21

PROJECT: 4
DUE DATE: November 24, 2019

Description:

Write a program that implements a link list to store input lines of text. The program will then print the list
constructed.

All nodes and string are to be allocated on the heap.
node structure:
address data
address next
nodes are to be added to the head of the list

int strlen(cstring soure) : returns the length of a source (‘\0’ not counted)
cstring strdup(cstring source) : returns a duplicate of source on the heap
address addnode(address data, address next) : returns an address to a new node initialized with data and next
traverse(address list, address proc) : traverses the list and calls proc passing the data of the node visit
main:
prompts the user for lines of text (up to 30 characters per line)
creates a link list of these lines head, the lines are to be created using strdup
outputs the call traverse(head, print)
print(cstring source) : output source to the terminal

Required I/O:
Link List by F. Last

Enter text? Line 1
Enter text? Line 2
Enter text? Enter

Line 2
Line 1
¶ is a blank line. F. Last is your first initial and last name, Enter is the Enter key

Turn in
Submit the source code to:

cp sllist.s /user/tvnguyen7/cs2640-002/username-sllist.s

Notes:
The following information is required in the beginning of every source file.
#
# Name: Last, First
# Project: #
# Due: date
# Course: cs-2640-02-f21
#
# Description:
# A brief description of the project.
#

Hints:

head: .word 0
input: .space ?

main:
do {
get a line of input
if input[0] == ‘\n’)
break
s = strdup(input)
head = addnode(s, head)
} while (true)
traverse(head, print)

addnode(s, list)
allocate node
node.data = s
node.next = list
return node

print(cstring s)
output s

traverse(list, proc)
if (list != 0) {
traverse(list.next)
}
proc(list.data)

11California State Polytechnic University