Small code reversal single linked list and reversal of the first k nodes of a single linked list

Source: Internet
Author: User

/******************** WZ Asust 2016
Code and Reflection   ********************/#include <iostream> #include <assert.h> #include <vector>// Container-class template #include<stdlib.h>//using random values #include<time.h>using namespace std;  #define  n  1000  #define  K 100 typedef struct node{    int x;          node *next;public:    node (): X ( 1)  ,next (null) {}    node (Int a): X (a),  next (null) {}}node;int xx[]={ 0,7,6,5,4,3,2,1,0};int i=0; void  linkcreat (Node*head) {if (head==null) {  head=new  node;} Head->x=xx[i++];while (i<8) {Node *add=new node (xx[i++]);add->next=head->next;head-> Next=add;}} Void show (node *head) {node *p=head; while (P) {cout<<p->x<< " ";p =p-> Next;} Cout<<endl;}   void v (Node *&head)  {  node *newheaD=head;node *p=head;node *q=head;node *t = null;  while (P->next!=NULL)   {     q=p;     p=p->next;      q->next=t;     t=q;      } head=p;  p->next=q; }void v (node *&head,int k)   { node *newhead= Head;node *p=head;node *q=head;node *t = null;  while (k--)   {      q=p;     p=p->next;     q- >next=t;     t=q;   }cout<<q->next->x<<endl;  head=q; newhead->next=p;  }int main () { node *head=new node (1);       linkcreat (head);           show (head);       v (head,4);      show (head);   }/********************* Blog   as a file broker   with memory retention There may be errors   Most programs only implement basic functionality when it comes to publishing   some of the fun for programmers who know the wrong thing is that they can write some code to get feedback part of the error left   In the subsequent blog references can be noted that the link list that section    function name and function mismatch    reversal is wrong   above has given the correct solution for the previous about array matching    is also wrong   It is important to change the test data when the project is in use *********************/


Small code reversal single linked list and reversal of the first k nodes of a single linked list

Related Article

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.