IIZeroHourII
Eternal Poster
- Joined
- Mar 16, 2016
- Posts
- 866
- Reaction
- 315
- Points
- 348
patulong sa mga master jan. bakit po same output lahat ng lumalabas sa mga inenter ko. tas hanggang 4 lang po ang kaya nyang node nag sstop working ung command line pag nag enter ng 5 node.
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
using namespace std;
struct employee
{
string name;
string position;
int salary;
employee *next;
};
employee *head;
void callme()
{
employee *temp, *newnode;
string temp_name;
string temp_position;
int temp_salary;
int n;
head=(employee *)malloc(sizeof(employee));
if(head==NULL)
{
cout<<"No size of head"<<endl;
}
cout<<"Enter number of node";
cin>>n;
cout<<"Enter Name : ";
cin>>temp_name;
cout<<"Enter Salary : ";
cin>>temp_salary;
cout<<"Enter Position : ";
cin>>temp_position;
head->name=temp_name;
head->salary=temp_salary;
head->position=temp_position;
head->next= NULL;
temp=head;
for(int i=2 ; i<=n ; i++)
{
newnode=(employee *)malloc(sizeof(employee));
if(newnode == NULL)
{
cout<<"No size for new node"<<endl;
}
cout<<"Enter name : ";
cin>>temp_name;
cout<<"Enter Salary : ";
cin>>temp_salary;
cout<<"Enter Position : ";
cin>>temp_position;
newnode->name=temp_name;
newnode->salary=temp_salary;
newnode->position=temp_position;
newnode->next=NULL;
temp->next=newnode;
temp=temp->next;
}
cout<<"name\t\t\tPosition\t\t\tsalary\t\t\t"<<endl;
while(head != NULL)
{
cout<<temp_name<<"\t\t\t"<<temp_position<<"\t\t\t"<<temp_salary<<endl;
head=head->next;
}
while(newnode != NULL)
{
cout<<temp_name<<"\t\t\t"<<temp_position<<"\t\t\t"<<temp_salary<<endl;
newnode=newnode->next;
}
}
int main()
{
callme();
}
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
using namespace std;
struct employee
{
string name;
string position;
int salary;
employee *next;
};
employee *head;
void callme()
{
employee *temp, *newnode;
string temp_name;
string temp_position;
int temp_salary;
int n;
head=(employee *)malloc(sizeof(employee));
if(head==NULL)
{
cout<<"No size of head"<<endl;
}
cout<<"Enter number of node";
cin>>n;
cout<<"Enter Name : ";
cin>>temp_name;
cout<<"Enter Salary : ";
cin>>temp_salary;
cout<<"Enter Position : ";
cin>>temp_position;
head->name=temp_name;
head->salary=temp_salary;
head->position=temp_position;
head->next= NULL;
temp=head;
for(int i=2 ; i<=n ; i++)
{
newnode=(employee *)malloc(sizeof(employee));
if(newnode == NULL)
{
cout<<"No size for new node"<<endl;
}
cout<<"Enter name : ";
cin>>temp_name;
cout<<"Enter Salary : ";
cin>>temp_salary;
cout<<"Enter Position : ";
cin>>temp_position;
newnode->name=temp_name;
newnode->salary=temp_salary;
newnode->position=temp_position;
newnode->next=NULL;
temp->next=newnode;
temp=temp->next;
}
cout<<"name\t\t\tPosition\t\t\tsalary\t\t\t"<<endl;
while(head != NULL)
{
cout<<temp_name<<"\t\t\t"<<temp_position<<"\t\t\t"<<temp_salary<<endl;
head=head->next;
}
while(newnode != NULL)
{
cout<<temp_name<<"\t\t\t"<<temp_position<<"\t\t\t"<<temp_salary<<endl;
newnode=newnode->next;
}
}
int main()
{
callme();
}