Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node
- {
- int number;
- node *next;
- };
- bool isEmpty(node *head)
- {
- if(head == NULL)
- return true;
- else
- return false;
- }
- void insertFirtElement(node *head, node *last, int number)
- {
- node *temp = new node;
- temp->number = number;
- temp->next =NULL;
- head = temp;
- last = temp;
- }
- void insert (node *head,node *last,int number)
- {
- if(isEmpty(head))
- insertFirtElement(head,last,number);
- else
- {
- node *temp = new node;
- temp->number = number;
- temp->next = NULL;
- last->next = temp;
- last = temp;
- }
- }
- void remove (node *head ,node *last)
- {
- if(isEmpty(head))
- cout<<"Lista jest pusta"<<endl;
- else if(head == last)
- {
- delete head;
- head == NULL;
- last ==NULL;
- }
- else
- {
- node *temp =head;
- head = head->next;
- delete temp;
- }
- }
- void showList(node*current)
- {
- if (isEmpty(current))
- cout<<"Lista jest pusta"<<endl;
- else
- {
- cout<<"Lista zawiera"<<endl;
- while(current !=NULL)
- {
- cout<<current->number <<endl;
- current =current->next;
- }
- }
- }
- int main()
- {
- node *head = NULL;
- node *last = NULL;
- getchar();
- return 0;
- }
- #include <iostream>
- using namespace std;
- struct element {
- char character;
- element *next;
- element *prev;
- };
- element *head = NULL;
- void addElement(char character)
- {
- element *last;
- element *temp = new element;
- temp->character = character;
- temp->next = NULL;
- temp->prev = NULL;
- if(head == NULL)
- head = temp;
- else
- {
- last = head;
- while(last->next!= NULL)
- last = last->next;
- last->next = temp;
- temp->prev = last;
- }
- }
- void show()
- {
- element *current;
- current = head;
- cout<<"Twoja lista"<<endl;
- while(current != NULL)
- {
- cout<<current->character <<endl;
- current= current->next;
- }
- }
- void remove()
- {
- element *temp=head;
- while (head!=NULL)
- {
- temp = head;
- head = head->next;
- cout<<"usuwam :"<<temp->character<<endl;
- delete temp;
- }
- }
- void search(char neded)
- {
- element *current = head;
- bool liczba= false;
- while (current!= NULL && current->character != neded)
- {
- current = current->next;
- if(current->character == neded)
- {
- liczba = true;
- }
- }
- if(liczba = false)
- cout<<"Nieznaleziono liczby"<<endl;
- else
- cout<<"znaleziono" <<endl;
- }
- int main()
- {
- addElement('a');
- addElement('b');
- addElement('c');
- addElement('d');
- addElement('e');
- show();
- search('a');
- search('d');
- search('k');
- search('x');
- remove();
- search('c');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement