- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
10_6.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //10_6.cpp
- #include <iostream.h>
- #include <iomanip.h>
- struct Student{
- int code;
- char name[20];
- char sex;
- unsigned age;
- };
- struct Node{
- Student* s;
- Node* next;
- };
- void Insert(Node*& head, Node*& t);
- void Display(const Node*& head);
- void main()
- {
- Student a[10] ={{8311001, "Smith", 'M', 18},
- {8512901, "Kerry", 'F', 19},
- {9022101, "Levy", 'M', 16},
- {8508020, "Doris", 'F', 20},
- {8881232, "Ella", 'F', 18},
- {9123001, "Carrie", 'M', 22},
- {8100825, "Barbara", 'F', 23},
- {9012120, "Carmen", 'M', 20},
- {8712001, "Brice", 'M', 19},
- {8100923, "Auden", 'M', 20}};
- Node* first=NULL;
- for(int i=0; i<10; i++){
- Node* pN = new Node;
- pN->s = &a[i];
- Insert(first, pN);
- }
- Display(first);
- }
- void Insert(Node*& head, Node*& t)
- {
- if(!head || t->s->code < head->s->code){
- t->next = head;
- head = t;
- return;
- }
- for(Node* p=head; p->next; p=p->next)
- if(t->s->code < p->next->s->code)
- break;
- t->next = p->next;
- p->next = t;
- }
- void Display(const Node*& head)
- {
- cout <<setiosflags(ios::left);
- for(const Node* p=head; p; p=p->next)
- cout <<setw(10) <<p->s->code
- <<setw(12) <<p->s->name
- <<setw(8) <<(p->s->sex=='M'?"male":"female")
- <<setw(6) <<p->s->age <<endl;
- }