Data Str & Algorithm HW Solutions 2

Data Str & Algorithm HW Solutions 2 - stores the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
2 Chap. 1 Data Structures and Algorithms // Concatenate two strings String strcat(String s1, String s2); // Return the length of a string int length(String s1); // Extract a substring, starting at ‘start’, // and of length ‘length’ String extract(String s1, int start, int length); // Get the first character char first(String s1); // Compare two strings: the normal C++ strcmp func- tion. Some // convention should be indicated for how to inter- pret the // return value. In C++, this is - 1 for s1<s2; 0 for s1=s2; // and 1 for s1>s2. int strcmp(String s1, String s2) // Copy a string int strcpy(String source, String destination) 1.4 The answer to this question is provided by the ADT for lists given in Chap- ter 4. 1.5 One’s compliment stores the binary representation of positive numbers, and
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: stores the binary representation of a negative number with the bits inverted. Two’s compliment is the same, except that a negative number has its bits inverted and then one is added (for reasons of ef f ciency in hardware imple-mentation). This representation is the physical implementation of an ADT de f ned by the normal arithmetic operations, declarations, and other support given by the programming language for integers. 1.6 An ADT for two-dimensional arrays might look as follows. Matrix add(Matrix M1, Matrix M2); Matrix multiply(Matrix M1, Matrix M2); Matrix transpose(Matrix M1); void setvalue(Matrix M1, int row, int col, int val); int getvalue(Matrix M1, int row, int col); List getrow(Matrix M1, int row);...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online