code for inserting element from end in a linked list ( not working!!)

This is the code
The program executes but as soon as i enter the first element it doesnt respond!!


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
56
57
58
59
60
61
62

#include <iostream>


using namespace std;
    void ins(int);
    void print();

struct Node { int inf;
              Node* next;
              };

    Node* temp;
    Node* last=NULL;


    int main ()

    { int x;
        char ch='y';
        while ( ch=='y'||ch=='Y')
        {
             cout<<"Enter the desired element ";
             cin>>x;
             cout<<endl;
             ins(x);
             print();
             cout<<"Wanna enter more elements?";
             cin>>ch;
        }

 return 0;
    }

    void ins(int a)

    {  temp= new Node;
       temp->inf=a;

       if(last=NULL)
       {

       last= temp;}

       else { last->next=temp;
              last=temp;


       }}

  void print()

  {
       while(temp!=NULL)

       {
            cout<<"The list now is ::: " <<temp->inf<<"  ";
            temp=temp->next;
       }
  }

if(last=NULL) // == not =
Topic archived. No new replies allowed.