Skip to content

Instantly share code, notes, and snippets.

@taishi41228
Created March 5, 2013 00:44
Show Gist options
  • Save taishi41228/5087069 to your computer and use it in GitHub Desktop.
Save taishi41228/5087069 to your computer and use it in GitHub Desktop.
#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