Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct list
- {
- int val;
- struct list *next;
- };
- void tofront(struct list **ppl)
- {
- struct list *tmp = *ppl;
- int n = 0;
- while(tmp != NULL)
- {
- ++n;
- tmp = tmp->next;
- }
- struct list *tmp1 = *ppl;
- int it = 0;
- while (it < n - (n / 3) - 1)
- {
- tmp1 = tmp1->next;
- ++it;
- }
- struct list *tmp2 = tmp1->next;
- tmp1->next = NULL;
- tmp->next = *ppl;
- *ppl = tmp1;
- }
- int main(void)
- {
- struct list *head = NULL;
- struct list *tmp = (struct list*)malloc(sizeof(struct list));
- tmp->val = 1;
- tmp->next = head;
- head = tmp;
- struct list *p = head;
- int res = tofront(&head);
- printf("%d", res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment