| |

VerySource

 Forgot password?
 Register
Search
View: 1442|Reply: 1

Master help to do it !!!!

[Copy link]

3

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-17 12:30:01
| Show all posts |Read mode
Design an algorithm to arrange the nodes in the original single linked list in reverse order. The nodes in the reversed single linked list are all the nodes in the original list.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-22 14:30:01
| Show all posts
#include"alloc.h"
typedef struct node
{
   int data;
   struct node *next;
}LinkedList;
  LinkedList *L;
LinkedList *create()
{LinkedList *head,*p;
  int x;
  head=malloc(sizeof(LinkedList));
  head->next=NULL;
  scanf("%d",&x);
  while(x!=999)
     {p=malloc(sizeof(LinkedList));
      p->data=x;
      p->next=head->next;
      head->next=p;
      scanf("%d",&x);
     }
   return(head);
  }
LinkedList *nizhi(LinkedList *head)
{LinkedList *r,*p=head->next;
  head->next=NULL;
  while(p!=NULL)
   {r=p->next;
     p->next=head->next;
     head->next=p;
     p=r;
    }
   return(head);
  }

void outdL(LinkedList *L)
{LinkedList *p;
  p=L->next;
  printf("\n\n");
  while(p!=NULL)
  {printf("%d",p->data);
     p=p->next;
       };
}
main()
{
  L=create();
  outdL(L);
  L=nizhi(L);
  outdL(L);
  }
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list