{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

This preview shows pages 1–5. Sign up to view the full content.

CS112 Fundamentals of Programming Abstractions Efficiency and ADTs Yinglin Wang CS Dept., SJTU CS112 Fundamentals of Programming Abstractions Solution to chp8 exercise 1 Main() { stackADT integerStack; int integer; integerStack=NewStack(); printf(”enter a list of integers, ending with 0:” ); while(TRUE){ printf(“>” ); scanf(“%d” ; &integer); if(integer!=0) Push(integerStack, integer); else break; } printf(“Those integers in reverse order are:” ) ; while(!StackIsEmpty){ pringtf(“\n %d” , Pop(integerStack)); } }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS112 Fundamentals of Programming Abstractions Solution to chp8 exercise 2 Main() { printf(”enter a list of integers, ending with 0:” ); reverseIntegers(void) } void reverseIntegers(void){ int integer; printf(“>” ); scanf(“%d” ; &integer); if(integer=0) { printf(“Those integers in reverse order are:” ) ; return; } else {reverseIntegers()}; printf(“\n%d” , integer); } CS112 Fundamentals of Programming Abstractions Different strategies for representing data can have a significant effect on the efficiency of yr code. linked list is a useful data structure for insertion and deletion operations. Main points:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS112 Fundamentals of Programming Abstractions Array Implementation of Editor Buffer struct bufferCDT { char text[MaxBuffer]; int length; int cursor; }; …… void MoveCursorBackward(bufferADT buffer) { if (buffer–>cursor > 0) buffer–>cursor–– ; } …… n The array implementation of the Editor Buffer leads to very straightforward code.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}