EXC BAD ACCESS意味着什么?参考我的代码意味着什么?

时间:2013-06-24 11:14:21

标签: linked-list

我的错误是什么意思?我该如何解决?

当我尝试运行程序时,请在此处查看错误照片...

http://postimg.org/image/horh6d26j/

我的程序正在尝试删除双链表的最后一个元素并将其插入前面

我只是尝试执行backToFront功能。 这项活动是2011年我大学的一项过去的实践考试(?) 我正在努力完成它以准备我的实践考试 - 这是两天之内 (aaahhhhhhh !!!!!!)

/*

 *  backToFront.c

 *  comp1917 pracExam #2 2011s1 UNSW

 *

 * Author: WRITE YOUR NAME HERE

 * Date: 21 June 2011

 * License: Public Domain

 */



// Implement the backToFront function below

// so that it moves the last node in a non-empty linked list

// of nodes to be the first node in the list, leaving the

// relative position of all the other nodes unchanged.



// You may assume the input list contains at least one node.

//

// Your function should do the moving by changing pointers

// in the nodes and list structs, (don't use malloc or make

// any new nodes)

//

// Your function should return the new list.

//

// You need to pass the tests in testBackToFront.c

//

// Compile and run the tests using

// gcc -Wall -Werror -O -o tester backtToFront.c testBackToFront.c

// ./tester

//

// When a test fails look in the testBackToFront.c file to see

// what the test was testing.  There are 3 tests in that file.

//

// Once you have passed all the tests you have finished.



#include <stdio.h>

#include <stdlib.h>

#include <assert.h>

#include "backToFront.h"



list backToFront (list items) {

assert (items.first != NULL);

nodePtr current = items.first;   
nodePtr previous = NULL;

while (current != NULL){
    previous = current;
    current = current->rest;
}

current->rest = items.first;
items.first = current;
previous->rest = NULL;




return items;

}

/*

 *  backToFront.h

 *  pracExam 2011

 *

 *  Created by Richard Buckland on 26/07/09.

 *  Modified by David Collien on 20/06/11.

 *  Copyright 2011. All rights reserved.

 *

 */



// DO NOT ALTER OR SUBMIT THIS FILE

// we will use our own copy when marking



typedef struct _node *nodePtr;



typedef struct _list {

    nodePtr first;

} list;



// For le sorution, add /samplesolutions at the end of your url

typedef struct _node {

    int      value;

    nodePtr  rest;

} node;



// given a node (*item) and a list of nodes (items)

// this function takes the last node of the list

// and moves it to be the first node in the list.

//

// the function returns the altered list.

//

// (note that the function does not create new nodes

// or change the value field of existing nodes.)

list backToFront (list items);

1 个答案:

答案 0 :(得分:0)

最有可能超出界限(该指数没有项目)。确保数组不为空