Language: Scheme Define a procedure called make-list that implements the List AD
ID: 3727375 • Letter: L
Question
Language: Scheme
Define a procedure called make-list that implements the List ADT using an object oriented design in Scheme. The make-list procedure should return a list object. (Note: The List object you'll create is different from a native Scheme list, however, the backing implementation of the List object may use a standard list).
The list object should have the following behaviours:
(size) - returns an integer equal to the number of items in the list
(get i) - returns the item stored at index i in the list
(set i x) - modifies index i in the list to hold item x
(add i x) - adds item x at index i in the list
(remove i) - removes and returns the item at index i from the list
(print) - displays the list in the standard scheme form (e.g. (a b c d))
For each of the functions, bad inputs (i.e. invalid indices) should be checked. Return #f for any operation that should return a value but fails. Your code should be written in such a way that the following interactions would be valid (note: this does not constitute a complete test suite):
Explanation / Answer
OUTPUT:
int main()
{
char str[100];
char splitStrings[10][10]; //can store 10 words of 10 characters
int i,j,cnt;
printf("Enter a string: ");
gets(str);
j=0; cnt=0;
for(i=0;i<=(strlen(str));i++)
{
// if space or NULL found, assign NULL into splitStrings[cnt]
if(str[i]==' '||str[i]=='')
{
splitStrings[cnt][j]='';
cnt++; //for next word
j=0; //for next word, init index to 0
}
else
{
splitStrings[cnt][j]=str[i];
j++;
}
}
printf(" Original String is: %s",str);
printf(" Strings (words) after split by space: ");
for(i=0;i < cnt;i++)
printf("%s ",splitStrings[i]);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.