struct listitem { struct listitem * next, prev; char c; }Some students went on for pages about destructors, constructors, and methods without giving describing the data structure itself.
Part B: Write, in legal Pascal, C or C++, the declarations of a function that will search the list described above; the function should take, as parameters, a character and a pointer to a doubly linked list, and it should return a pointer to the node in the list that contains that character, or a null pointer in the case that the character is not found in the list.
struct listitem * search( struct listitem * list, char c) { while (list != NULL) { if (list->c == c) return list; list = list->next; } return NULL }
int atoi( char * ptr, int base ); { char * p = ptr; int value = 0; while (isxdigit(*p)) { int digit; if (isdigit(*p)) { digit = *p - '0'; } else if (isupper(*p)) { digit = *p - 'A' + 10; } else { digit = *p - 'a' + 10; } if (digit >= base) error(); value = value * base + digit; p++; } return value; }The above will work for bases up to 16 using the standard C function isxdigit, and if isxdigit is redefined as isalnum (true if isalpha or isdigit), it will work for bases up to 36.
556 = 5x6 + 5 = 35
5556 = 5x36 + 5x6 + 5 = 215
558 = 5x8 + 5 = 45
5558 = 5x64 + 5x8 + 5 = 365
D00B16 = 13x163 + 11 = 53259
1ED016 = 1x163 + 14x162 + 13x16 + 0 = 7888
IOWA34
= Ix343 + Ox342 + Wx34 + A
= 18x343 + 24x342 + 32x34 + 10
= 736314
The string is this! 001000: 20656854 001004: 69727473 001008: 6920676E 00100C: 68742073 001010: xx217369
Part A: How much memory can you attach to this machine, in words?
14 bit memory addresses allow 214 distinct addresses, and this allows addressing of 214 different words of memory, or 16384 words.
Part B: How many characters of text could you store in the memory of this machine?
Each word is 16 bits, so 2 8-bit characters could be stored there. This gives a total memory capacity of 32768 characters.
10: 01 11: 32 12: 54 13: 76