?? sortcpp.cpp
字號:
/******Don't forget to download*****
*****GRAPHICAL DATA FILE STRUCTURE*****
*****A approach to learn DFS Graphically*****
Only @ http://www.vivekpatel.cjb.net */
//LinkList Sorting
#include <iostream.h>
#include <conio.h>
struct node{
int data;
struct node *next;
};
class link{
node *head;
public:
void create();
void display();
void sort();
};
void link :: create(){
node *newl=NULL,*end=newl;
int data;
head=NULL;
cout<<"\n**Create List**\n";
cout<<"\nEnter -999 to terminate\n";
while(1){
cout<<"Enter Data Value : ";
cin>>data;
if(data==-999)
break;
else{
newl = new node;
newl->data=data;
if(head==NULL)
head=newl;
else
end->next=newl;
end=newl;
end->next=NULL;
}
}
cout<<"\nList is Created\n";
getch();
}
void link :: display(){
node *start;
start=head;
cout<<"\n**Display**\n";
while(start!=NULL){
cout<<start->data;
if(start->next!=NULL)
cout<<"==>";
start=start->next;
}
cout<<"\nDisplay's End\n";
getch();
}
void link :: sort(){
cout<<"\n**Linear Sort**\n";
node *i, *j;
int temp;
for(i=head;i!=NULL;i=i->next){
for(j=i->next;j!=NULL;j=j->next){
if(i->data > j->data){
temp = i->data;
i->data = j->data;
j->data = temp;
}
}
}
cout<<"\nData are Sorted\n";
getch();
}
void main(){
int choice;
link obj;
while(1){
clrscr();
cout<<"****LinkList Sorting Demo****"<<endl;
cout<<"1) Create List\n";
cout<<"2) Display List\n";
cout<<"3) Sort List\n";
cout<<"4) Exit\n";
cout<<"Enter your choice : ";
cin>>choice;
switch(choice){
case 1 : obj.create();
break;
case 2 : obj.display();
break;
case 3 : obj.sort();
break;
case 4 : goto out;
default : cout<<"\nInvalid Choice\n";
}
}
out:
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -