Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct node
- {
- int num;
- struct node *next;
- }node;
- node *makenode(int key)
- {
- node *newnode = (node*)malloc(sizeof(node));
- if (!newnode)
- return NULL;
- newnode->num = key;
- newnode->next = NULL;
- return newnode;
- }
- node * add_last(node *head, node* newItem)
- {
- node *currItem;
- if (!head)
- return newItem;
- currItem = head;
- while (currItem->next)
- currItem = currItem->next;
- currItem->next = newItem;
- return head;
- }
- node *func(node *head)
- {
- node *current = head;
- int max;
- max = current->num;
- node *prev;
- while (current->next)
- {
- if (max < current->next->num)
- {
- max = current->next->num;
- prev = current;
- }
- current = current->next;
- }
- prev->next = prev->next->next;
- free(current);
- return head;
- }
- void main() {
- int res;
- node * head;
- head = makenode(6);
- head = add_last(head, makenode(3));
- head = add_last(head, makenode(5));
- head = add_last(head, makenode(7));
- head = add_last(head, makenode(1));
- node *temp= func(head);;
- while (temp)
- {
- printf("%d", temp->num);
- temp = temp->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement