{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS112_23_Slides-Editorbuffer

# CS112_23_Slides-Editorbuffer - Efficiency and ADTs Yinglin...

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

S112 Fundamentals of rogramming Abstractions Efficiency and ADTs Yinglin Wang CS Dept., SJTU

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

View Full Document
S112 Fundamentals of rogramming Abstractions Our website moved to 202.120.1.155/wang-yl/index.htm ftp site remains 202.120.7.244
S112 Fundamentals of rogramming Abstractions Solution to 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
S112 Fundamentals of rogramming Abstractions Solution to exercise 2 Main() { printf(”enter a list of integers, ending with 0:”); reverseIntegers(); } 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); }
S112 Fundamentals of rogramming 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
S112 Fundamentals of rogramming Abstractions Today we will discuss the implementation of an Editor Buffer, which is the topic of your next assignment. An Editor Buffer is the data structure that underlies text editing programs like Notepad. The first implementation we will consider is based on arrays. The picture here is the demonstration of program.

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

View Full Document
S112 Fundamentals of rogramming 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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 31

CS112_23_Slides-Editorbuffer - Efficiency and ADTs Yinglin...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online