Skip to content

Instantly share code, notes, and snippets.

@bombless
Forked from pezy/birthday.cpp
Last active August 29, 2015 14:08
Show Gist options
  • Save bombless/481960b83be4fd5f788e to your computer and use it in GitHub Desktop.
Save bombless/481960b83be4fd5f788e to your computer and use it in GitHub Desktop.
//
// main.cpp
// Test
//
// Created by pezy on 9/11/14.
// Copyright (c) 2014 PEZY. All rights reserved.
//
#include<iostream>
using namespace std;
struct member{
char name[4];
int year;
int month;
member *next;
};
void Insert(member* &pHead, member* &pNode){
if(pHead == NULL){
pHead = pNode;
return;
}
if(pNode->year < pHead->year || (pNode->year == pHead->year && pNode->month < pHead->month)){
pNode->next = pHead;
pHead = pNode;
return;
}
member *p = pHead;
member *q = p->next;
while(p->next != NULL){
if((pNode->year > p->year || (pNode->year == p->year && pNode->month > p->month))
&&(pNode->year < q->year || (pNode->year == q->year && pNode->month <= q->month))){
pNode->next = p->next;
p->next = pNode;
return;
}
p = q;
q = q->next;
}
p->next = pNode;
}
void Input(member* &head){
member *pNode = new member;
cin >> pNode->name >> pNode->year >> pNode->month;
pNode->next = NULL;
Insert(head, pNode);
return;
}
void Output(member* head){
member *p = head;
for(int i = 0; i < 7; i++) {
cout << p->name <<" "<< p->year <<"."<< p->month <<endl;
p = p->next;
}
}
int main(){
member *head = NULL;
for(int i = 0; i < 7; i++)
Input(head);
Output(head);
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment