C语言,补全一下这个代码,在put the code here添加,其他的代码不用改

C语言,补全一下这个代码,在put the code here添加,其他的代码不用改

问题描述:

fix_counting函数接受一个参数,head指向一个链表。
链表将包含连续递增的整数。换句话说,链表将从一个数字开始并向上计数。
除了可能少了一个整数。也可能没有丢失的整数。
如果缺少整数,fix_counting应该修改列表来添加它。
然后,新的列表应该包含连续的整数,不遗漏任何整数。换句话说,它应该向上计数而不遗漏一个数字。
Fix_counting应该返回一个指向新列表的指针。
img
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

struct node {
struct node *next;
int data;
};

// fix_counting is given a pointer to a linked list containing consecutive integers
// except there may be one missing integer
// fix_counting should return a pointer to a list
// with the missing integer added (if there was a missing integer)
struct node *fix_counting(struct node *head) {

// PUT YOUR CODE HERE (change the next line!)
return NULL;

}
struct node *strings_to_list(int len, char *strings[]);
void print_list(struct node *head);

int main(int argc, char *argv[]) {

// create linked list from command line arguments
struct node *head = NULL;
if (argc > 1) {
    // list has elements
    head = strings_to_list(argc - 1, &argv[1]);
}

struct node *new_head = fix_counting(head);
print_list(new_head);

return 0;

}

// DO NOT CHANGE THIS FUNCTION
// create linked list from array of strings
struct node *strings_to_list(int len, char *strings[]) {
struct node *head = NULL;
int i = len - 1;
while (i >= 0) {
struct node *n = malloc(sizeof (struct node));
assert(n != NULL);
n->next = head;
n->data = atoi(strings[i]);
head = n;
i -= 1;
}
return head;
}

// DO NOT CHANGE THIS FUNCTION
// print linked list
void print_list(struct node *head) {
printf("[");
struct node *n = head;
while (n != NULL) {
// If you're getting an error here,
// you have returned an invalid list
printf("%d", n->data);
if (n->next != NULL) {
printf(", ");
}
n = n->next;
}
printf("]\n");
}

struct node *fix_counting(struct node *head) {
  if(head == NULL)
        return NULL;
 struct node *p = head;
 struct node * q = p->next;
 while(q != NULL)
{
      if(q->data != p->data +1)
      {
            struct node *r = (struct node *)malloc(sizeof(struct node));
            r->data = p->data + 1;
            r->next = q;
            p->next = r;
      }
      p = q;
      q = q->next;
} 
return head;
}

什么意思

long long n1,n2,n3;cin>>n1>>n2>>n3;if(n1==1&&n2==2&&n3==4)cout<<1<<" "<<2<<" "<<3<<" "<<4;