Programalama > C++

Etiketler: data, structure, link, list

Ort. 0
Puan ver:
*************
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 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.