Created
March 5, 2013 00:44
-
-
Save taishi41228/5087069 to your computer and use it in GitHub Desktop.
リスト構造 ref: http://qiita.com/items/0f3c0ddd6283171358dc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
struct node{ | |
char data; | |
struct node* next; | |
}; | |
/* リストの検索 */ | |
int listSearch( struct node* head, char str ){ | |
int count = 0; | |
struct node* p; | |
p = head; | |
while (p != NULL) { | |
count ++; | |
if( p->data == str ){ | |
return count; /* xが存在する */ | |
} | |
p = p->next; | |
} | |
return -1; /* xが存在しない */ | |
} | |
/* リストの表示 */ | |
void listUp( struct node* head ){ | |
struct node* p; | |
p = head; | |
while (p != NULL) { | |
printf("%s\n",p->data); | |
p = p->next; | |
} | |
printf("\n"); | |
} | |
void enqueue(struct node** hp){ | |
struct node* p; | |
p = *hp; | |
*hp = p->next; | |
free(p); | |
} | |
void dequeue(struct node** hp, char str[]){ | |
struct node* p; | |
/* リストが空の場合 */ | |
if ( *hp == NULL ){ | |
p = *hp = malloc( sizeof(struct node) ); | |
} | |
/* リストが空でない場合 */ | |
else{ | |
p = *hp; | |
/* リストの末尾までたどる */ | |
while ( p->next != NULL ) { | |
p = p->next; | |
} | |
p->next = malloc( sizeof(struct node) ); | |
p = p->next; | |
} | |
p->data = *str; | |
p->next = NULL; | |
} | |
int main(int argc, char *argv[]) { | |
struct node *head; | |
char* str="aaaa"; | |
dequeue(&head,str); | |
listUp( head ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment