900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > java数组的声明学号姓名线性结构_定义一个结构体数组 包含学号 姓名 成绩三哥成员项。...

java数组的声明学号姓名线性结构_定义一个结构体数组 包含学号 姓名 成绩三哥成员项。...

时间:2019-03-12 05:33:07

相关推荐

java数组的声明学号姓名线性结构_定义一个结构体数组 包含学号 姓名 成绩三哥成员项。...

sorry,没时间另外写一个了。类似题目的回答很多的。个人建议结构体操作用链表方式,如果用数组方式的话,对于有效记录数的掌控不方便,比如插入要考虑数组长度不能越界,删除要考虑有效记录的减少等等。输入字数有限制,只能给你些程序段了。

typedef struct _node{

int num;

struct _node *next;

} Node, *pNode;

pNode CreateTestNode(int re, int len)

{

pNode head, cur, tail;

int i;

head = cur = tail = NULL;

for(i = 0; i num = i + re;

cur->next = NULL;

if(!head)

{

head = tail = cur;

}

else

{

tail->next = cur;

tail = tail->next;

}

}

return head;

}

int PrintAllNode(const pNode head) //显示链表元素数据

{

Node const * ph = head;

while(ph)

{

printf("%d ",ph->num);

ph = ph->next;

}

printf("\n");

}

pNode Insert(pNode ph, int n) //1.在一个有序表中插入一个元素,使得该表仍然有序。

{

pNode head = ph, tmp,cur;

if(NULL == (tmp = (pNode)malloc(sizeof(*cur))))

return ph;

tmp->num = n;

while(head && head->num next;

}

if(ph == head)

{

tmp->next = head;

return tmp;

}

tmp->next = cur->next;

cur->next = tmp;

return ph;

}

pNode reverse(pNode h)//将一个链表中的所有元素逆序存储

{

pNode tmphead,tmptail, head = h;

tmphead = tmptail = NULL;

while(head->next)

{

if(!tmphead)

{

tmphead = tmptail = head;

head = head->next;

tmptail->next = NULL;

}

else

{

tmphead = head;

head = head->next;

tmphead->next = tmptail;

tmptail = tmphead;

}

}

head->next = tmphead;

return head;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。