@iwktd981220
2017-09-19T07:14:46.000000Z
字数 2108
阅读 387
问问题
1、这个表达中,为什么可以直接 L->next = p;
这个表示的是L的next指针指向p的什么?
LinkedList LinkedListCreatH()
{
Node *L;
L = (Node *)malloc(sizeof(Node)); //申请头结点空间
L->next = NULL; //初始化一个空链表
ElemType x; //x为链表数据域中的数据
while(scanf("%d",&x) != EOF)
{
Node *p;
p = (Node *)malloc(sizeof(Node)); //申请新的结点
p->data = x; //结点数据域赋值
p->next = L->next; //将结点插入到表头L-->|2|-->|1|-->NULL
L->next = p;
}
return L;
}
2、输出下列三个值的不同,并标明输出的内容表示什么(表达是否正确):
int main() {
int i=0,o=2;
int *pi =&i; //pi的内存指针指向i的地址
printf("*pi :%i\n", *pi );
*pi =1; //pi的内存指向1
printf("%i\n", i );
printf("pi:%p\n", pi ); //pi的内存地址
pi=&o; //pi等于o的地址???
printf("%i\n", pi); //输出pi的值
printf("%p\n", pi); //输出指针pi储存的o的地址???
printf("%i\n", *pi); //输出pi所指内存中的值(&o的地址),然后就等于*&o=2
printf("%p\n", *pi); //输出指针pi
return 0;
}
3、在使用指针时出现了这样的error,无法解决
lianbiao.c: In function ‘main’:
lianbiao.c:17:5: error: ‘*l’ is a pointer; did you mean to use ‘->’?
l ->next = NULL;
^~
->
lianbiao.c:22:14: error: ‘*new_node’ is a pointer; did you mean to use ‘->’?
new_node -> next = l ->next;
^~
->
lianbiao.c:22:26: error: ‘*l’ is a pointer; did you mean to use ‘->’?
new_node -> next = l ->next;
^~
->
lianbiao.c:23:14: error: ‘*new_node’ is a pointer; did you mean to use ‘->’?
new_node ->num = x ;
^~
->
lianbiao.c: In function ‘delete’:
lianbiao.c:31:33: error: ‘*entry’ is a pointer; did you mean to use ‘->’?
for (size_t i = 1; i < entry->num -1; i++) {
^~
->
lianbiao.c:32:20: error: ‘*list’ is a pointer; did you mean to use ‘->’?
list = list->next;
^~
->
lianbiao.c:38:16: error: ‘*list’ is a pointer; did you mean to use ‘->’?
list = list->next;
^~
->
lianbiao.c:39:17: error: ‘*list’ is a pointer; did you mean to use ‘->’?
list = list ->next;
^~
->
lianbiao.c:41:7: error: ‘*o’ is a pointer; did you mean to use ‘->’?
o ->next = p;
^~
->
#include <stdio.h>
#include <stdlib.h>
typedef struct _list_t {
int num;
struct _list_t *next;
}*list_t;
list_t *delete(list_t* l,list_t *entry) ;
int main() {
list_t *l;
list_t *new_node;
list_t *list;
list_t *entry;
scanf("%i", l );
l ->next = NULL;
int x;
while (scanf(" %i ", &x ) != EOF) {
list_t *n;
new_node=(list_t*)malloc(sizeof(list_t));
new_node -> next = l ->next;
new_node ->num = x ;
}
return 0;
}
list_t *delete(list_t *l,list_t *entry) {
list_t *list;
list = l;
for (size_t i = 1; i < entry->num -1; i++) {
list = list->next;
}
list_t *o,*p,*q;
o = (list_t*)malloc(sizeof(list_t));
*o = *list;
p = (list_t*)malloc(sizeof(list_t));
list = list->next;
list = list ->next;
*p = *list ;
o ->next = p;
return l;
}