我刚刚开始学习c语言中的指针,并且我正在由stephen G. Kochan用c语言进行编程中的练习题。问题之一是
我已经回答了这个问题,因为它非常简单。下面是它的源代码
#include<stdio.h>
struct entry
{
int value;
struct entry *next;
};
void insertEntry(struct entry *newPtr,struct entry *afterPtr);
int main(void)
{
struct entry n1,n2,n3;
struct entry *startPtr=&n1;
n1.value=100;
n1.next=&n2;
n2.value=200;
n2.next=&n3;
n3.value=300;
n3.next=(struct entry *)0;
struct entry n2_3;
n2_3.value=250;
insertEntry(&n2_3,&n2);
struct entry *listPtr;
listPtr=startPtr;
while(listPtr!=(struct entry *)0)
{
printf("%i ",listPtr->value);
listPtr=listPtr->next;
}
printf("\n");
return 0;
}
void insertEntry(struct entry *newPtr,struct entry *afterPtr)
{
newPtr->next=afterPtr->next;
afterPtr->next=newPtr;
}
我坚持的另一个问题是
无论如何我都想不出第二个问题。任何前进的有用提示或想法都将非常有帮助。另外,我知道这不是一个辅导网站,但是我试图自己学习这些东西,没有人可以联系,如果有人帮助我前进,我将非常感激。
您可以定义链接列表的类型,该列表具有对列表标题的引用:
struct list {
struct entry *head;
};
void insert_head(struct list *list, struct entry *node) {
node->next = list->head;
list->head = node;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句