Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "prog.h"
- using namespace std;
- list::list(){
- head=NULL;
- tail=NULL;
- }
- //insert functions
- void list::push(int n){
- node *temp=new node;
- temp->data=n;
- temp->next=head;
- head=temp;
- }
- void list::insert_place(int place, int n){
- node *temp=new node;
- node *pre_cycle=new node;
- node *cycle=new node;
- cycle=head;
- if(place==1){
- push(n);
- }else{
- for (int i=1; i<place; i++){
- pre_cycle=cycle;
- cycle=cycle->next;
- }
- temp->data=n;
- pre_cycle->next=temp;
- temp->next=cycle;
- }
- }
- void list::insert_end(int n){
- node *last = new node;
- node *temp = new node;
- last->data=n;
- last->next=NULL;
- temp=head;
- while(temp->next!=NULL){
- temp=temp->next;
- }
- temp->next=last;
- }
- //delete functions
- void list::delete_start(){
- node *temp=new node;
- temp=head;
- head=head->next;
- delete temp;
- }
- void list::delete_place(int place){
- node *pre_cycle=new node;
- node *cycle=new node;
- cycle=head;
- if(place==1){
- delete_start();
- }else{
- for (int i=1; i<place; i++){
- pre_cycle=cycle;
- cycle=cycle->next;
- }
- pre_cycle->next=cycle->next;
- }
- }
- void list::delete_end(){
- node *last = new node;
- node *temp = new node;
- last->next=NULL;
- temp=head;
- while(temp->next!=NULL){
- temp=temp->next;
- }
- temp->next=last;
- delete temp;
- }
- int list::size(){
- node *temp = new node;
- int size=0;
- temp=head;
- while(temp!=NULL){
- size++;
- temp=temp->next;
- }
- return size;
- }
- //sorting functions
- bool list::compare(node *a, node *b){
- return(a->data > b->data);
- }
- void list::swap(node *a, node *b){
- node *temp = new node;
- if(a==head){
- head=b;
- a->next=b->next;
- b->next=a;
- return;
- }
- while(temp->next!=a){
- temp=temp->next;
- }
- temp->next=b;
- a->next=b->next;
- b->next=a;
- }
- //fix this trash
- void list::bubble_sort(){
- node *first = new node;
- first=head;
- while(first&&first->next!=NULL){
- node *temp = new node;
- for(temp=first; temp->next!=NULL;temp=temp->next){
- //if(compare(temp, temp->next)){
- // swap(temp->next, temp);
- //}
- }
- }
- }
- //output functions
- void list::display(){
- node *temp=new node;
- temp=head;
- while(temp!=NULL){
- cout<<temp->data<<endl;
- temp=temp->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement