Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #define flush getchar();
- struct data{
- char nama[50];
- int umur;
- struct data *next, *prev;
- }*head, *tail, *curr;
- void AddFront(char nama[], int umur){
- curr=(struct data*)malloc(sizeof(struct data));
- strcpy(curr->nama, nama);
- curr->umur=umur;
- curr->next=curr->prev=NULL;
- if(head==NULL)
- head=tail=curr;
- else{
- curr->next=head;
- head->prev=curr;
- head=curr;
- }
- }
- void AddBack(char nama[], int umur){
- curr=(struct data*)malloc(sizeof(struct data));
- strcpy(curr->nama, nama);
- curr->umur=umur;
- curr->next=curr->prev=NULL;
- if(head==NULL)
- head=tail=curr;
- else{
- curr->prev=tail;
- tail->next=curr;
- tail=curr;
- }
- }
- void AddMid(char nama[], int umur){ //Ascending
- data *temp;
- curr=(struct data*)malloc(sizeof(struct data));
- strcpy(curr->nama, nama);
- curr->umur=umur;
- curr->next=curr->prev=NULL;
- if(head==NULL)
- head=tail=curr;
- else if(head->umur > curr->umur)
- AddFront(nama, umur);
- else if(tail->umur < curr->umur)
- AddBack(nama, umur);
- else{
- temp=head;
- while(temp->next->umur<curr->umur){
- temp=temp->next;
- }
- if(temp->next->umur>curr->umur){
- curr->next=temp->next;
- temp->next=curr;
- }
- }
- }
- void DelFront(){
- if(head!=NULL){
- if(head==tail){
- free(head);
- head=tail=NULL;
- }
- else{
- head=head->next;
- free(head->prev);
- head->prev=NULL;
- }
- }
- }
- void DelAll(){
- while(head!=NULL){
- DelFront();
- }
- }
- void DelBack(){
- if(head!=NULL){
- if(head==tail){
- free(head);
- head=tail=NULL;
- }
- else{
- tail=tail->prev;
- free(tail->next);
- tail->next=NULL;
- }
- }
- }
- void ShowData(){
- int i=1;
- curr=head;
- while(curr!=NULL){
- printf("%d %s %d\n", i, curr->nama, curr->umur);
- i++;
- curr=curr->next;
- }
- }
- void Search(){
- char key[50];
- gets(key);
- curr=head;
- while(curr!=NULL){
- if(strcmp(key, curr->nama)==0){
- printf("%d", curr->umur);
- curr=curr->next;
- }
- }
- }
- int main(){
- char nama[50];
- int umur;
- flush;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment