Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct Elem {
- struct Elem *next;
- char *word;
- };
- struct Elem *InitSingleLinkedList()
- {
- struct Elem *list = (struct Elem*)malloc(sizeof(struct Elem));
- list->next = NULL;
- list->word = "xex";
- return list;
- }
- struct Elem *bsort(struct Elem *list)
- {
- return list;
- }
- int main()
- {
- char *cur = (char*)malloc(100000 * sizeof(char));
- struct Elem *l = InitSingleLinkedList();
- struct Elem *c = l;
- struct Elem *f;
- int n = 0, len, i;
- while (1) {
- scanf("%s", cur);
- len = (int)strlen(cur);
- if (len != 0) {
- struct Elem *now = (struct Elem*)malloc(sizeof(struct Elem));
- now->word = cur;
- c->next = now;
- c = now;
- n++;
- }
- else break;
- }
- c = l->next;
- for (i = 0; i < n; i++) {
- printf("%s ", c->word);
- c = c->next;
- }
- c = l->next;
- for (i = 0; i < n; i++) {
- f = c->next;
- free(c);
- c = f;
- }
- free(cur);
- free(l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement