Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define N -1000000000
- struct Node {
- int n;
- struct Node *next;
- };
- struct Node *createNode(int n) {
- struct Node *elem = (struct Node *) malloc(sizeof(struct Node));
- elem->n = n;
- elem->next = NULL;
- return elem;
- };
- int max_elem(struct Node *head) {
- int max = N;
- while(head!=NULL){
- if(head->n > max){
- max = head->n;
- }
- head = head->next;
- }
- return max;
- }
- int main() {
- char end = ' ';
- int n;
- struct Node *head;
- struct Node *elem;
- struct Node *prev;
- for (int i = 0; i < 10; i++) {
- scanf("%d%c", &n, &end);
- elem = createNode(n);
- if (i == 0) {
- head = elem;
- prev = head;
- continue;
- }
- prev->next = elem;
- prev = elem;
- if (end == '\n')
- break;
- }
- printf("%d", max_elem(head));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement