不同于市面上的用c++写的noj,此文章由c写,符合在校生需求,且附有注释,希望能赞助,且看我慢慢更新。
代码由vs写。
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node* next;
}Lnode, *Listnode;
int n;
int ray[1005];
void array()
{
int i;
for (i = n - 1; i >= 0; i--)
{
printf("%d ", ray[i]);
}
printf("\n", ray[i]);
}
void list()
{
Listnode rear, p, head;
head = (Listnode)malloc(sizeof(Lnode));
head->next = NULL;
int i;
for (i = 0; i <= n - 1; i++)
{
p = (Listnode)malloc(sizeof(Lnode));
p->data = ray[i];
p->next = head->next;
head->next = p;
}
p = head->next;//此处没有对head.next的值进行检查
while (p)
{
printf("%d ", p->data);//勿忘空格,否则粘连
p = p->next;
}
}
int main()
{
int i;
scanf_s("%d", &n);
for (i = 0; i <= n - 1; i++)
{
scanf_s("%d", &ray[i]);
}
array();
list();
}