[ create a new paste ] login | about

Link: http://codepad.org/L2poK8dq    [ raw code | output | fork ]

C++, pasted on Aug 24:
#include<iostream>
#include<cstdlib>
using namespace std;

int y = 100;
struct node {
  int x;
  node *next;
};

node* add_element(node*);
bool is_empty(node*);
void print_list(node*);
node* search(node*);
int main()
{
  node *head;
    head=NULL;
    node* current=head;
    for(int i=0;i<5;i=i+1)
        {

            current=add_element(current);

        }
        head=current;
        cout<<head->next<<endl;
// DOUBT: head->next gives NULL value. It should give me pointer to 2nd node.
print_list(head);
}



  node* add_element(node* current)
  {   
    node* temp;
    temp=new node;
    temp->next=NULL;
    cout<<"enter element"<<endl;
    temp->x = y--; 
    temp->next = current;
    return temp; 
  }

  bool is_empty(node* temp)
  {
    return temp==NULL;

    }

void print_list(node* temp)
{
    if (is_empty(temp)==false)
    {   cout<<"here temp(head)"<<temp->next<<endl;
        while(temp!=NULL)
        {
        cout<<temp->x<<endl;
        temp = temp->next;
        }

    }
    }


Output:
1
2
3
4
5
6
7
8
9
10
11
12
enter element
enter element
enter element
enter element
enter element
0x80514b0
here temp(head)0x80514b0
96
97
98
99
100


Create a new paste based on this one


Comments: