Position Find( List L, ElementType X ); List Insert( List L, ElementType X, Position P ); List Delete( List L, Position P );
intmain() { List L; ElementType X; Position P, tmp; int N;
L = NULL; scanf("%d", &N); while ( N-- ) { scanf("%d", &X); L = Insert(L, X, L); if ( L==ERROR ) printf("Wrong Answer\n"); } scanf("%d", &N); while ( N-- ) { scanf("%d", &X); P = Find(L, X); if ( P == ERROR ) printf("Finding Error: %d is not in.\n", X); else { L = Delete(L, P); printf("%d is found and deleted.\n", X); if ( L==ERROR ) printf("Wrong Answer or Empty List.\n"); } } L = Insert(L, X, NULL); if ( L==ERROR ) printf("Wrong Answer\n"); else printf("%d is inserted as the last element.\n", X); P = (Position)malloc(sizeof(struct LNode)); tmp = Insert(L, X, P); if ( tmp!=ERROR ) printf("Wrong Answer\n"); tmp = Delete(L, P); if ( tmp!=ERROR ) printf("Wrong Answer\n"); for ( P=L; P; P = P->Next ) printf("%d ", P->Data); return0; }
/* 你的代码将被嵌在这里 */
输入样例:
1 2 3 4
6 12 2 4 87 10 2 4 2 12 87 5
输出样例:
1 2 3 4 5 6 7 8
2 is found and deleted. 12 is found and deleted. 87 is found and deleted. Finding Error: 5 is not in. 5 is inserted as the last element. Wrong Position for Insertion Wrong Position for Deletion 10 4 2 5
List MakeEmpty(); Position Find( List L, ElementType X ); boolInsert( List L, ElementType X, Position P ); boolDelete( List L, Position P );
intmain() { List L; ElementType X; Position P; int N;
L = MakeEmpty(); scanf("%d", &N); while ( N-- ) { scanf("%d", &X); if ( Insert(L, X, 0)==false ) printf(" Insertion Error: %d is not in.\n", X); } scanf("%d", &N); while ( N-- ) { scanf("%d", &X); P = Find(L, X); if ( P == ERROR ) printf("Finding Error: %d is not in.\n", X); else printf("%d is at position %d.\n", X, P); } scanf("%d", &N); while ( N-- ) { scanf("%d", &P); if ( Delete(L, P)==false ) printf(" Deletion Error.\n"); if ( Insert(L, 0, P)==false ) printf(" Insertion Error: 0 is not in.\n"); } return0; }
/* 你的代码将被嵌在这里 */
输入样例:
1 2 3 4 5 6
6 1 2 3 4 5 6 3 6 5 1 2 -1 6
输出样例:
1 2 3 4 5 6 7 8
FULL Insertion Error: 6 is not in. Finding Error: 6 is not in. 5 is at position 0. 1 is at position 4. POSITION -1 EMPTY Deletion Error. FULL Insertion Error: 0 is not in. POSITION 6 EMPTY Deletion Error. FULL Insertion Error: 0 is not in.