Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include<iostream>
- #include<string>
- using namespace std;
- struct Node
- {
- int key;
- Node *next;
- };
- Node *head;
- //error
- void error(char *s)
- {
- cout << s << endl;
- exit(1);
- }
- //add Node (front)
- void add_front(int info)
- {
- Node *tmp;
- tmp = new Node;
- if (tmp == NULL)
- error("add_front: out of memory");
- tmp->key = info;
- tmp->next = head;
- head = tmp;
- }
- //print Nodes
- void print()
- {
- Node *pos;
- pos = head;
- while(pos != NULL)
- {
- cout << pos->key << "\t";
- pos = pos->next;
- }
- cout << endl;
- }
- void removeNode(int key)
- {
- Node *pos;
- pos = head;
- while(pos != NULL)
- {
- if(pos->key == key)
- {
- //TODO: let the pointer if the las Node point to this->next Node
- }
- pos = pos->next;
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- Node *p;
- add_front(3);
- add_front(2);
- add_front(1);
- add_front(0);
- removeNode(1);
- print();
- char f;
- cin >> f;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement