Linked list experts - URGENT CALL

Please someone helps me with this question I must submit the answer tomorrow. The program is not working properly as is suppose to ; I am not getting the result shown below.


Write a program that accepts numbers from the user and stores them in a linked list called allnum until a negative number is entered, then after the input has been terminated print the elements stored in the linked list . then without allocation of new memory place all even numbers in allnum in the linked list even ,and all the odd numbers in the linked list odd. Finally print the two linked list with proper heading.

Example :

Enter the integer values, - to stop: 2 5 8 3 9 6 1 7 4 -9

The result will be:

The numbers in the linked list are: 2 5 8 3 9 6 1 7 4
The numbers in the even linked list are: 2 8 6 4
The numbers in the odd linked list are: 5 3 9 1 7

This is my program

#include <stdio.h>
#include <stdlib.h>

struct list *make_node(int );

struct list *insert(struct list *,struct list *);


struct list
{
int num;
struct list *next;
};

main()
{
struct numbers *start, *ptr, *head=NULL;


int count=0,input;



printf("Enter a integer.\n");

while (scanf("%d",&input));
{
ptr=make_node(input);
if (count==0)
{
start=ptr;
count++;
}

head=insert(head,ptr);
}


}


struct list *make_node(int numb)
{
struct list *pt;

pt=(struct list *)malloc( sizeof(struct list) );

if (pt==NULL)
{
printf("No more memory.\n");
exit(0);
}
pt->num=numb;

return pt;
}

struct list *insert(struct list *start,struct list *pt)
{
struct list *a=start;

pt->next=start;
start=pt;

return start;
}

return ;

}
Last edited on
Your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
//it would be better to use <iostream>

struct list *make_node(int );//'struct' is used to dclare a struct. You don't need it here
struct list *insert(struct list *,struct list *);//nor here


struct list{
    int num;
    struct list *next;//nor here
};

main(){//it's int main.
    struct numbers *start, *ptr, *head=NULL;//struct numbers does not exist.
    int count=0,input;

    printf("Enter a integer.\n");//use <iostream>

    while (scanf("%d",&input));{
        ptr=make_node(input);
        if (count==0){
            start=ptr;
            count++;
        }
        head=insert(head,ptr);
    }
    //you need to return sth here
}


struct list *make_node(int numb){//you dont need 'struct'
    struct list *pt;// same here
    pt=(struct list *)malloc( sizeof(struct list) );//and here

    if (pt==NULL){
        printf("No more memory.\n");
        exit(0);
    }
    pt->num=numb;
    return pt;
}

struct list *insert(struct list *start,struct list *pt){//and here
    struct list *a=start;//you never use this 'a'

    pt->next=start;
    start=pt;

    return start;
}

return ;// 'return' has to be in a function

}//what is this doing here?  


Did you even try to compile it?
Last edited on
Topic archived. No new replies allowed.