Programalama > C++

Etiketler: data, structure, link, list

Ort. 0
Puan ver:
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
*************
Main.Cpp*
************
#include <iostream.h>
#include "llist.h"
 
 
 
void main()
    {
     
     
    int data;//value which passes to link
    number link;
 
    cout<<"--------------------------------------------------------------------------\n"
        <<"Link List Program                                                        |\n"
        <<"USAGE: Enter The Numbers From The Keyboard in random order               |\n"
        <<"       Program Will give them to you in ascending order from up to bottom|\n"
        <<"--------------------------------------------------------------------------\n"
        <<"\nEnter Your Numbers:(-1 For Exit)\n"
        <<"--->";
     
    cin>>data;
     
    while(data>-1){//take the values
        link.add(data);
        cout<<"--->";
        cin>>data;
        if(data==-1){//exit msg
            cout<<"END\n"
                <<"Those Ar The Numbers U Have Entered(Given In Ascending Order)\n";
            link.print();
        }//if
 
    }//while
 
}//main
 
//MasterG 2004
 
************
LList.cpp*
************
#include <iostream>
#include "llist.h"
using namespace std;
 
 
 
number::number(){//constructor
    head=NULL;
    cur=NULL;
    pre=NULL;
 
}
 
 
void number::add(int num){//adding function
     
    node *temp=NULL;
     
    if(head==NULL) {//IsEmpty?
        head=new node;
        head->num=num;
        head->next=NULL;
         
    }//end of if
     
    else if(head->num > num){//Is Entered Num < Head?
        cur=head;
        head=NULL;
        head=new node;
        head->num=num;
        head->next=cur;
         
    }//end of if
    else {//Else Fınd The Correct Node For Entered Num
         
        cur=head;
         
        while(cur && cur->num <= num){
            pre=cur;
            cur=cur->next;
        }
 
        temp=new node;
        temp->num=num;
        temp->next=cur;
        pre->next=temp;
         
    }//end of if
     
}//end of add func.
 
 
 
 
void number::print(){//print
 
        cur=head;
        cout<<"START->";
        while(cur!=NULL){
            cout<<cur->num<<" >";
            cur=cur->next;
        }//while
 
}//print
 
 
 
**********
LList.h *
**********
 
#ifndef LLIST_H
#define LLIST_H
 
 
struct node{
 
    int num;//data
    node *next;
};
 
 
class number{
public://public members
 
    number();//constr.
 
    void add(int num);//adding values to list
    void print();//print
     
     
private://private members
    node *head;
    node *cur;
    node *pre;
};
#endif


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2025 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.