staticintMaxSubSum(constint A[], int Left, int Right) { int MaxLeftSum, MaxRightSum; int MaxLeftBorderSum, MaxRightBorderSum; int LeftBorderSum, RightBorderSum; int Center, i;
// Base Case if(Left == Right) { if(A[Left] > 0) { return A[Left]; } else { return0 } }
Center = (Left + Right)/2; // assume N is even MaxLeftSum = MaxSubSum(A, Left, Center); MaxRightSum = MaxSubSum(A, Center + 1; right);
List MakeEmpty(List L); intIsEmpty(List L); intIsLast(Position P, List L); Position Find(ElementType X, List L); voidDelete(ElementType X, List L); Position FindPrevious(ElementType X, List L); voidInsert(ElementType X, List L, Position P); voidDeleteList(List L); Position Header(List L); Position First(List L); Position Advance(Position P); ElementType Retrieve(Position P);
#endif/* _List_H */
// Place in the implementation file structNode { ElementType Element; Position Next; };
// Return true if L is empty intIsEmpty(List L) { return L->Next == NULL; }
// Return true if P is the last position in list L // Parameter L is unused in this implementation intIsLast(Position P, List L) { return P->Next == NULL; }
// Return Position of X in L; NULL if not found Position Find(ElementType X, List L) { Position P;
P = L->Next; while(P != NULL && P->Element != X) { P = P->Next; }
return P; }
// Delete first occurrence of X from a list // Assume use of a header node voidDelete(ElementType X, List L) { Position P, TempCell;
P = FindPrevious(X, L);
if(!IsLast(P, L)) { // Assumption of header use // X is found, delete it TempCell = P->Next; P->Next = TempCell->Next; // Bypass deleted cell free(TempCell); } }
// If X is not found, then next field of returned // Position is NULL // Assumes a header Position FindPrevious(ElementType X, List L) { Position P;
P = L; while(P->Next != NULL && P->Next->Element != X) { P = P->Next; } return P; }
// Insert (after legal position P) // Header implementation assumed // Parameter L is unused in this implementation voidInsert(ElementType X, List L, Position P) { Position TmpCell;