1 条题解

  • 0
    @ 2024-12-24 9:48:49

    C :

    #include<stdio.h>
    #include<stdlib.h>
    typedef struct tagNODE
    {
    	int number;
    	struct tagNODE* next;
    }node, * linklist;
    void InputAndCreate(linklist* L)
    {
    	linklist p, s;
    	int n;
    	p = *L = (linklist)malloc(sizeof(node));
    	while (scanf("%d", &n), n >= 0)
    	{
    		s = (linklist)malloc(sizeof(node));
    		s->number = n;
    		p->next = s, p = s;
    	}
    	p->next = NULL;
    }
    void rOutput(linklist L)
    {
    	L = L->next;
    	if (L->next != NULL)
    	{
    		rOutput(L);
    		printf("%d ", L->number);
    	}
    	else
    	{
    		printf("%d ", L->number);
    		return;
    	}
    }
    int main()
    {
    	linklist list;
    	InputAndCreate(&list);
    	rOutput(list);
    	return 0;
    }
    

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    
    struct node{
    	int data;
    	node *next;
    };
    
    void Travel(node *head){
    	while(head!=NULL){
    		cout<<head->data<<" ";
    		head = head->next;
    	} 
    }
    int main()
    {
    	node *p,*h,*head;
    	p=NULL;
    	int x;
    	while(cin>>x&&x!=-1){
    		h = new node;
    		h->data = x; 
    		h->next = p;
    		p = h;
    	} 
    	head = p;
    	Travel(head);
    	return 0;
    }
    
    
    • 1

    信息

    ID
    752
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者