Click here to Skip to main content
16,020,298 members

Comments by Hatta Schmidt (Top 5 by date)

Hatta Schmidt 19-Dec-12 2:20am View    
Deleted
below my new code but it will loop forever if i insert 3-sort:

#include <iostream>
#include <cstdlib>
#include <string.h>
#include <iomanip>
#include <windows.h>
using namespace std;
struct node
{
int mark;
char name[10];
struct node *next;
} *person=NULL,*head=NULL,*temp=NULL,*next=NULL,*head1=NULL;

void SortList();
void Insert();

void Menu()
{
cout<<"1.Insert data."<<endl;
cout<<"2.Display data."<<endl;
cout<<"3.Sort data based on highest mark."<<endl;
cout<<"4.Exit."<<endl;
cout<<"Enter Your choice: ";
}

void Insert()
{
person =new node;
char name[10];
cout<<endl;
cout<<"Enter Your name: ";
cin>>person->name;
cout<<"Enter Your mark: ";
cin>>person->mark;
cout<<endl;

if (head == NULL)
{
head = person;
person->next = NULL;
}
else
{
person->next = head;
head = person;
}
}

void Print()
{
temp = head;
int i = 1;

cout<<"-----LIST CONTENTS-----"<<endl<<endl;
cout<<"No"<<setw(10)<<"Name"<<setw(10)<<"Marks"<<endl;

if (temp == NULL)
cout<<"List is empty!!";
else
{
while (temp != NULL)
{
cout<<i<<setw(10)<<temp->name<<setw(10)<<temp->mark<<endl;
temp = temp->next;
i++;
}

}
cout<<endl;
}

void SortedInsert()
{
temp = head;
if (head == NULL)
{
head = person;
person->next = NULL;
}
else
{
if (person->mark > temp->mark)
{
person->next = temp;
head = person;

}
else
{
while ((temp->next != NULL) && (temp->next->mark > person->mark))
{
temp = temp-> next;
}

person->next=temp->next;
temp->next = person;

}
}
}


void SortList()
{

person = head;
if (person == NULL)
cout<<"List empty"<<endl;
else
{
while (person != NULL)
{
next = person->next;
SortedInsert();
person=next;
}

}


cout<<"Sorted list: "<<endl;

}
int main (int argc, const char * argv[])
{

int choice;
cout<<"===This Program to insert name and mark==="<<endl;
cout<<endl;
do
{
Menu();
cin>>choice;
switch (choice)
{
case 1:
Insert();
break;
case 2:
Print();
break;
case 3:
SortList();
Print();
break;
default:
cout<<"\nWRONG CHOICE";
}
} while (choice != 0);

return 0;
}
Hatta Schmidt 19-Dec-12 2:18am View    
Thanks..but i still don't get the correct one.please help me,what kind of code that i need to replace it.
Hatta Schmidt 18-Dec-12 7:25am View    
which part u edit Jochen Arndt??
this program nothing happen when i choose number 3-sort data based on high mark.
please someone help me!!Thanks
Hatta Schmidt 18-Nov-11 21:49pm View    
i have another question..how to make file processing on this code..hopefully anyone can help me..please!
Hatta Schmidt 15-Nov-11 21:39pm View    
thank you for remind me..actually i just new in this web..finally i got to solve this problem..thanks you..but i want to ask u another question,how to appear menu such as...
1.new game
2.instruction
3.exit

this menu will be appear before game is start.then when user click 1,it will run and so on..
hopefully you can help me..im very appreciate to u..i think you are intelegence in this field..