Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <stdlib.h>
- #include <cstring>
- #define SIZE 10
- using namespace std;
- struct rlink
- {
- char data[SIZE];
- rlink* next;
- };
- class St
- {
- private:
- char* str1,* sp;
- rlink* first;
- int l1, l2;
- public:
- St(char* s1)
- {
- first=NULL;
- l1=strlen(s1); //l2=strlen(s2);
- str1 = new char[l1+1];
- //str2 = new char[l2+1];
- strcpy(str1,s1); //strcpy(str2,s2);
- }
- void fun()
- {
- for(int n=0, m=0;m<strlen(str1);m++)
- {
- if(str1[m]!=' ')
- {sp[n]=str1[m]; n++;
- cout << &str1 <<' '<<&sp<< endl;
- }
- else
- {
- sp[n]='\0';
- rlink* newlink = new rlink;
- strcpy(newlink->data,sp);
- newlink->next = first;
- first = newlink;
- //cout << newlink->next << endl;
- n=0;
- }
- }
- return;
- }
- void disp()
- {
- rlink* cur = first;
- while(cur!=NULL)
- {
- cout << cur->data << ' ' << cur->next << endl;
- cur=cur->next;
- }
- return;
- }
- ~St()
- {
- delete []str1;
- cout << "deleted1\n";
- //cout << "deleted2\n";
- //delete []str2;
- }
- };
- int main()
- {
- char di[100];
- //char di2[100];
- cin.getline(di, sizeof(di));
- //cin.getline(di2, sizeof(di2));
- St list(di);
- list.fun();
- list.disp();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement