我在确定给定算法要求的内容时遇到问题。我不知道如何删除数组中的位置或者为数组中的最后一个位置指定null。这是算法:
found = searchToDelete( course )
IF (found == -1) THEN
Display message that course is not in student’s schedule
ELSE
IF (found == ( position of last course in array) THEN
course number = course number -1
ELSE
FOR (index = found, index < course number, index++)
schedule [index] = schedule [index + 1]
END FOR
course number = course number - 1
END IF
END IF
这是我的代码:
public void dropCourse(String courseName){
found = searchToDelete(course);
int index = 0;
if (found == -1){
System.out.println("Course not in schedule");
if (found = index(6)){
courseNumber = courseNumber -1;
for ( index = found, index < courseNumber, index ++);
{
schedule[index] = schedule[index + 1];
}courseNumber = courseNumber -1;
}
}
}