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;
}