Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #define null ((void *)0)
- typedef long long LL;
- typedef struct _model {
- char NIM[11];
- char name[200];
- char gender;
- LL income;
- struct _model *next;
- struct _model *prev;
- } Model;
- Model *head = null;
- Model *tail = null;
- Model *current = null;
- Model* create_new(const char NIM[11], const char name[200], const char& gender, const LL income) {
- Model *temp = (Model*)malloc(sizeof(Model));
- memcpy(temp->name, name, (strlen(name) + 1) * sizeof(char));
- temp->gender = gender;
- temp->income = income;
- temp->next = temp->prev = null;
- return temp;
- }
- void push_head() {
- current->next = head;
- head->prev = current;
- head = current;
- head->prev = null;
- }
- void push_tail() {
- tail->next = current;
- current->prev = tail;
- tail = current;
- tail->next = null;
- }
- void add(const char NIM[11], const char name[200], const char& gender, const LL income) {
- current = create_new(name, gender, income);
- if(head == null) {
- head = tail = current;
- } else if(head == tail) {
- if(income > head->income) {
- push_head();
- } else {
- push_tail();
- }
- } else {
- Model *temp = head;
- while(temp != null) {
- if(income <= temp->income) {
- temp = temp->next;
- } else {
- break;
- }
- }
- if(temp == head) {
- push_head();
- } else if(temp == null) {
- push_tail();
- } else {
- Model *before = temp->prev;
- before->next = current;
- current->prev = before;
- current->next = temp;
- temp->prev = current;
- }
- }
- }
- void main_menu() {
- }
- int main() {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement