Reverse single-linked list (0957) Swust-oj

Source: Internet
Author: User

Description

Create a single-linked list of length n, then invert its data elements, that is, the 1th element becomes the last element, the 2nd element becomes the 2nd element, ..., and the last element becomes the 1th element. (The data type processed is a character type.) You must use a linked list to complete. )

Input

The first behavior is the list length n; the value of n data elements in the second behavior list.

OutputThe original value after the inverse. Sample input10a B C D E F G H I Sample Output I H G F E D C B A Analysis: Inverse system, only need to use the head interpolation method to establish a single-linked list; Code:

#include <stdio.h>
#include <malloc.h>
typedef struct NODE
{
Char str[100];
struct Node*next;
}node;
void Create (node*&l,int N)//head interpolation
{
node*s;
int i;
L= (node*) malloc (sizeof (Node));
l->next=null;
for (i=0;i<n;i++)
{
S= (node*) malloc (sizeof (Node));
scanf ("%s", S->STR);
s->next=l->next;
l->next=s;
}
}
int main ()
{
Node*l;
int total;
scanf ("%d", &total);
Create (l,total);
Node*read;
read=l->next;
while (read)
{
printf (read->next? ") %s ":"%s", read->str);//output format, control last one more space
read=read->next;
}
return 0;

}

Reverse single-linked list (0957) Swust-oj

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.