Ytu 2430:c language exercise linked list set up, insert, delete, output

Source: Internet
Author: User
2430:c language Exercise list set up, insert, delete, outputTime limit: 1 Sec Memory limit: 128 MB
Submitted: 576 settlement: 280
Topic Description

Write a function Creatlink to create a dynamic linked list. (including school numbers and grades)
Write a function Printlink to output a linked list.
Write a function Dellink to delete a specified node in a dynamic list (a number specified by the argument to delete the student node).
Write a function insertlink to insert a node into the dynamic list.
Write a function Freelink to release a dynamic list. input

Enter a number of students and scores, set up dynamic linked list to 0 0 to end
Input number, delete the corresponding node in the list
Insert two linked list node output

Output of the linked list sample input

1001
1002
1005
1008
0 0
1005 1006
1009 99
Sample Output
1001 100.00
1002 95.00 1006 98.00 1008 76.00
1009 99.00
Tips

The main function is given as follows, and the following main functions are not required for submission



/* C code * *

int main ()

{

struct student *creatlink (void);

struct student *dellink (struct student *,long);

struct student *insertlink (struct student *,struct student *);

void Printlink (struct student *);

void Freelink (struct student *);

struct student *head,stu;

Long Del_num;

Head=creatlink ();

scanf ("%ld", &del_num);

Head=dellink (Head,del_num);

scanf ("%ld%f", &stu.num,&stu.score);

Head=insertlink (Head,&stu);

scanf ("%ld%f", &stu.num,&stu.score);

Head=insertlink (Head,&stu);

Printlink (head);

Freelink (head);

return 0;

}



/* C + + code * *



int main ()

{

Student *creatlink (void);

Student *dellink (student *,long);

Student *insertlink (Student *,student *);

void Printlink (student *);

void Freelink (student *);

Student *head,stu;

Long Del_num;

Head=creatlink ();

cin>>del_num;

Head=dellink (Head,del_num);

cin>>stu.num>>stu.score;

Head=insertlink (Head,&stu);

cin>>stu.num>>stu.score;

Head=insertlink (Head,&stu);

Cout<<setiosflags (ios::fixed);

Cout<<setprecision (2);

Printlink (head);

Freelink (head);

return 0;

}

lost in the valley of the birds, flying alone in this huge world, but do not know where to fly to the side ...

#include <stdio.h> #include <iostream> #include <stdlib.h> #include <string.h> #include <
Iomanip> using namespace std;
    struct Student {long int num;
    Float score;
struct student *next;
};
    struct Student *creatlink () {struct student *p1,*p2,*head=null;
    p1=p2= (struct student*) malloc (sizeof (struct student)); while (~SCANF ("%ld%f", &p1->num,&p1->score) && (p1->score| |
        P1->num)) {if (head==null) head=p1;
        else p2->next=p1;
        P2=P1;
    p1=p1->next= (struct student*) malloc (sizeof (struct student));
    } p2->next=null;
return head;
};
    struct student *dellink (struct student *a,long b) {struct student;
        while (P!=null) {if (p->num==b) p2->next=p->next;
        P2=p;
    p=p->next;
return head;
};
  struct student *insertlink (struct student *a,struct student *b) {struct student *head=a,*p=a,*p2=a,*k;  k= (struct student*) malloc (sizeof (struct student));
    k->num=b->num,k->score=b->score;
    int n=0;
            while (P!=null) {if (p->num>b->num) {p2->next=k;
            k->next=p;
        N=1;
        } p2=p;
    p=p->next;
    } if (n==0) p2->next=k,k->next=null;
return head;
};
    void Printlink (struct student *a) {struct student;
        while (P!=null) {printf ("%ld%.2f\n", P->num,p->score);
    p=p->next;
        } void Freelink (struct student *a) {while (a!=null) {Delete (a);
    a=a->next;
    int main () {student *creatlink (void);
    Student *dellink (student *,long);
    Student *insertlink (Student *,student *);
    void Printlink (student *);
    void Freelink (student *);
    Student *head,stu;
    Long Del_num;
    Head=creatlink ();
    cin>>del_num;
    Head=dellink (Head,del_num);
    cin>>stu.num>>stu.score; HEad=insertlink (Head,&stu);
    cin>>stu.num>>stu.score;
    Head=insertlink (Head,&stu);
    Cout<<setiosflags (ios::fixed);
    Cout<<setprecision (2);
    Printlink (head);
    Freelink (head);
return 0; }

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.